import { z } from 'zod';

export const NOTE_TASK_STATUSES = ['open', 'in_progress', 'completed', 'canceled'] as const;
export type NoteTaskStatus = (typeof NOTE_TASK_STATUSES)[number];

export interface NoteTaskDoc {
  id: string;
  productId: string;
  workspaceId: string;
  userId: string;
  noteId: string;
  title: string;
  description?: string;
  status: NoteTaskStatus;
  dueAt?: string;
  source: 'manual' | 'extracted';
  createdAt: string;
  createdBy: string;
  updatedAt: string;
  updatedBy: string;
  _ts?: number;
  _etag?: string;
}

export const CreateNoteTaskSchema = z.object({
  id: z.string().min(1).max(128),
  workspaceId: z.string().min(1).max(128),
  noteId: z.string().min(1).max(128),
  title: z.string().min(1).max(500),
  description: z.string().max(4000).optional(),
  dueAt: z.string().datetime().optional(),
  source: z.enum(['manual', 'extracted']).default('manual'),
});

export const UpdateNoteTaskSchema = z.object({
  title: z.string().min(1).max(500).optional(),
  description: z.string().max(4000).optional(),
  status: z.enum(NOTE_TASK_STATUSES).optional(),
  dueAt: z.string().datetime().optional(),
});

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

export type CreateNoteTaskInput = z.infer<typeof CreateNoteTaskSchema>;
export type UpdateNoteTaskInput = z.infer<typeof UpdateNoteTaskSchema>;
export type ListNoteTasksQuery = z.infer<typeof ListNoteTasksQuerySchema>;
