/**
 * Group entity types
 *
 * Groups are user-managed flat containers that organize entities (assistants,
 * topics, sessions) under a chosen entityType. Ordering within an entityType is
 * preserved via a fractional-indexing `orderKey`.
 */

import * as z from 'zod'

import { EntityTypeSchema } from './entityType'

// ============================================================================
// Group Entity
// ============================================================================

export const GroupIdSchema = z.uuidv4()
export const GroupNameSchema = z.string().trim().min(1).max(64)

/**
 * Complete Group entity as returned by the API.
 */
export const GroupSchema = z.strictObject({
  /** Group ID (UUID v4, auto-generated by database) */
  id: GroupIdSchema,
  /** Entity type this group belongs to (tag / group / pin share the enum) */
  entityType: EntityTypeSchema,
  /** Display name of the group */
  name: GroupNameSchema,
  /** Fractional-indexing order key within this entityType */
  orderKey: z.string().min(1),
  /** Creation timestamp (ISO string) */
  createdAt: z.iso.datetime(),
  /** Last update timestamp (ISO string) */
  updatedAt: z.iso.datetime()
})
export type Group = z.infer<typeof GroupSchema>
