import { z } from 'zod';

const PrioritySchema = z.enum(["LOW", "MEDIUM", "HIGH", "URGENT"]);
const boardDateFields = {
  createdAt: z.coerce.date().optional(),
  updatedAt: z.coerce.date().optional()
};
const boardCoreFields = {
  name: z.string().min(1, "Name is required"),
  slug: z.string().min(1, "Slug is required"),
  description: z.string().optional(),
  ownerId: z.string().optional(),
  organizationId: z.string().optional()
};
const BoardDomainSchema = z.object({
  id: z.string().optional(),
  ...boardCoreFields,
  ...boardDateFields
});
const createBoardSchema = BoardDomainSchema.extend({
  slug: BoardDomainSchema.shape.slug.optional()
}).omit({ id: true });
const updateBoardSchema = BoardDomainSchema.extend({
  id: z.string()
}).partial().required({ id: true });
const columnDateFields = {
  createdAt: z.coerce.date().optional(),
  updatedAt: z.coerce.date().optional()
};
const columnCoreFields = {
  title: z.string().min(1, "Title is required"),
  order: z.number().int().min(0).optional().default(0),
  boardId: z.string().min(1, "Board ID is required")
};
const ColumnDomainSchema = z.object({
  id: z.string().optional(),
  ...columnCoreFields,
  ...columnDateFields
});
const createColumnSchema = ColumnDomainSchema.omit({ id: true });
const updateColumnSchema = ColumnDomainSchema.extend({
  id: z.string()
}).partial().required({ id: true });
const taskDateFields = {
  completedAt: z.coerce.date().optional(),
  createdAt: z.coerce.date().optional(),
  updatedAt: z.coerce.date().optional()
};
const taskCoreFields = {
  title: z.string().min(1, "Title is required"),
  description: z.string().optional(),
  priority: PrioritySchema.optional().default("MEDIUM"),
  order: z.number().int().min(0).optional().default(0),
  columnId: z.string().min(1, "Column ID is required"),
  assigneeId: z.string().optional().nullable(),
  isArchived: z.boolean().optional().default(false)
};
const TaskDomainSchema = z.object({
  id: z.string().optional(),
  ...taskCoreFields,
  ...taskDateFields
});
const createTaskSchema = TaskDomainSchema.omit({ id: true });
const updateTaskSchema = TaskDomainSchema.extend({
  id: z.string()
}).partial().required({ id: true });
const BoardListQuerySchema = z.object({
  slug: z.string().optional(),
  ownerId: z.string().optional(),
  organizationId: z.string().optional(),
  offset: z.coerce.number().int().min(0).optional(),
  limit: z.coerce.number().int().min(1).max(100).optional()
});
z.object({
  boardId: z.string().optional()
});
z.object({
  columnId: z.string().optional(),
  assigneeId: z.string().optional(),
  priority: PrioritySchema.optional(),
  isArchived: z.string().optional().transform((val) => {
    if (val === void 0) return void 0;
    if (val === "true") return true;
    if (val === "false") return false;
    return void 0;
  })
});
const reorderColumnsSchema = z.object({
  boardId: z.string().min(1, "Board ID is required"),
  columnIds: z.array(z.string()).min(1, "Column IDs are required")
});
const reorderTasksSchema = z.object({
  columnId: z.string().min(1, "Column ID is required"),
  taskIds: z.array(z.string()).min(1, "Task IDs are required")
});
const moveTaskSchema = z.object({
  taskId: z.string().min(1, "Task ID is required"),
  targetColumnId: z.string().min(1, "Target column ID is required"),
  targetOrder: z.number().int().min(0)
});

export { BoardDomainSchema, BoardListQuerySchema, ColumnDomainSchema, PrioritySchema, TaskDomainSchema, createBoardSchema, createColumnSchema, createTaskSchema, moveTaskSchema, reorderColumnsSchema, reorderTasksSchema, updateBoardSchema, updateColumnSchema, updateTaskSchema };
