import { z } from "zod"

export const payrollItemSchema = z.object({
  id: z.string().optional(),
  type: z.enum(["ADDITION", "DEDUCTION"]),
  description: z.string().min(1, "Description is required"),
  amount: z.number().nonnegative("Amount must be positive"),
})

export const payrollSchema = z.object({
  id: z.string().optional(),
  employeeId: z.string().min(1, "Employee is required"),
  month: z.number().int().min(1).max(12, "Month must be between 1 and 12"),
  year: z.number().int().min(2000).max(2100, "Invalid year"),
  workingDays: z.number().int().min(1).max(31).default(30),
  daysWorked: z.number().int().min(0).max(31).default(30),
  basicSalary: z.number().nonnegative("Basic salary must be positive"),
  items: z.array(payrollItemSchema).default([]),
  notes: z.string().optional(),
  status: z.enum(["DRAFT", "APPROVED", "PAID"]).default("DRAFT"),
})

export const payrollProcessSchema = z.object({
  status: z.enum(["APPROVED", "PAID"]),
  approvedAt: z.date().optional(),
})

export type PayrollInput = z.infer<typeof payrollSchema>
export type PayrollItemInput = z.infer<typeof payrollItemSchema>
