import { z } from 'zod';

export const RELATIONSHIP_TYPES = [
  'related',
  'references',
  'parent',
  'child',
  'duplicate',
  'task-source',
  'artifact-source',
] as const;
export type RelationshipType = (typeof RELATIONSHIP_TYPES)[number];

export interface NoteRelationshipDoc {
  id: string;
  productId: string;
  workspaceId: string;
  userId: string;
  fromNoteId: string;
  toNoteId: string;
  relationshipType: RelationshipType;
  createdAt: string;
  createdBy: string;
  updatedAt: string;
  updatedBy: string;
  _ts?: number;
  _etag?: string;
}

export const CreateNoteRelationshipSchema = z.object({
  id: z.string().min(1).max(128),
  workspaceId: z.string().min(1).max(128),
  fromNoteId: z.string().min(1).max(128),
  toNoteId: z.string().min(1).max(128),
  relationshipType: z.enum(RELATIONSHIP_TYPES),
});

export const ListNoteRelationshipsQuerySchema = z.object({
  workspaceId: z.string().min(1).max(128),
  noteId: z.string().min(1).max(128).optional(),
  relationshipType: z.enum(RELATIONSHIP_TYPES).optional(),
  limit: z.coerce.number().int().min(1).max(100).default(50),
  offset: z.coerce.number().int().min(0).default(0),
});

export type CreateNoteRelationshipInput = z.infer<typeof CreateNoteRelationshipSchema>;
export type ListNoteRelationshipsQuery = z.infer<typeof ListNoteRelationshipsQuerySchema>;
