import { objectId } from '@jig-software/zod-bson';
import { z } from 'zod';
import { LeaveInit } from './Leave';
import { LeaveType } from './LeaveType';

export const LeaveApplicationStatus = z.enum([
  'pending',
  'approved',
  'rejected',
  'canceled',
]);
export type LeaveApplicationStatus = z.infer<typeof LeaveApplicationStatus>;

export const LeaveApplication = z.object({
  _id: objectId(),
  status: LeaveApplicationStatus,
  leaves: z.array(LeaveInit).min(1),
  leaveBalanceAfter: z.record(LeaveType, z.number().optional()),
  applyRemarks: z.string().nullish(),
  approveRemarks: z.string().nullish(),
  rejectRemarks: z.string().nullish(),
  cancelRemarks: z.string().nullish(),
  appliedBy: objectId(),
  canceledAt: z.date().nullish(), // TODO: Implement cancel
  canceledBy: objectId().nullish(), // TODO: Implement cancel
  rejectedAt: z.date().nullish(),
  rejectedBy: objectId().nullish(),
  approvedAt: z.date().nullish(),
  approvedBy: objectId().nullish(),
  needProof: z.boolean().optional(),
  proofSubmitted: z.boolean().optional(),
  createdAt: z.date(),
  updatedAt: z.date(),
});

export type LeaveApplication = z.infer<typeof LeaveApplication>;
