/**
 * Pin entity types
 *
 * Pins are a polymorphic non-destructive "promote to top" marker. Any entity
 * type participating in the shared `EntityType` enum can be pinned by its id.
 * Ordering is preserved per entityType via a fractional-indexing `orderKey`.
 */

import * as z from 'zod'

import { EntityIdSchema, EntityTypeSchema } from './entityType'

// ============================================================================
// Pin Entity
// ============================================================================

export const PinIdSchema = z.uuidv4()

/**
 * Complete Pin entity as returned by the API.
 */
export const PinSchema = z.strictObject({
  /** Pin ID (UUID v4, auto-generated by database) */
  id: PinIdSchema,
  /** Entity type this pin targets (tag / group / pin share the enum) */
  entityType: EntityTypeSchema,
  /** Target entity id (UUID v4 or UniqueModelId) */
  entityId: EntityIdSchema,
  /** 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 Pin = z.infer<typeof PinSchema>
