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

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

export const LeaveCreditApplication = z.object({
  _id: objectId(),
  status: LeaveCreditApplicationStatus,
  leaveType: LeaveType,
  amount: z.number(),
  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(),
  createdAt: z.date(),
  updatedAt: z.date(),
});

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

export const LeaveCreditInit = LeaveCreditApplication.pick({
  leaveType: true,
  amount: true,
  applyRemarks: true,
});
export type LeaveCreditInit = z.infer<typeof LeaveCreditInit>;
