// import { Injectable, NotFoundException, BadRequestException } from "@nestjs/common";
// import { UpsertLeaveRequestDto, UpsertResult } from "src/time-and-attendance/leave-requests/dtos/upsert-leave-request.dto";
// import { LeaveTypes, LeaveApprovalStatus } from "@prisma/client";
// import { leaveRequestsSelect } from "src/time-and-attendance/utils/selects.utils";
// import { LeaveRequestViewDto } from "src/time-and-attendance/leave-requests/dtos/leave-request-view.dto";
// import { LeaveRequestsUtils } from "src/time-and-attendance/leave-requests/utils/leave-request.util";
// import { BankCodesResolver } from "src/time-and-attendance/utils/resolve-bank-type-id.utils";
// import { EmailToIdResolver } from "src/time-and-attendance/utils/resolve-email-id.utils";
// import { HolidayService } from "src/time-and-attendance/domains/services/holiday.service";
// import { PrismaPostgresService } from "src/prisma/prisma.service";
// import { mapRowToView } from "src/time-and-attendance/leave-requests/mappers/leave-requests.mapper";
// import { normalizeDates, toDateOnly } from "src/time-and-attendance/utils/date-time.utils";
// import { Result } from "src/common/errors/result-error.factory";



// @Injectable()
// export class HolidayLeaveRequestsService {
//     constructor(
//         private readonly prisma: PrismaPostgresService,
//         private readonly holidayService: HolidayService,
//         private readonly leaveUtils: LeaveRequestsUtils,
//         private readonly emailResolver: EmailToIdResolver,
//         private readonly typeResolver: BankCodesResolver,
//     ) { }

//     async create(dto: UpsertLeaveRequestDto): Promise<Result<UpsertResult, string>> {
//         const email = dto.email.trim();
//         const employee_id = await this.emailResolver.findIdByEmail(email);
//         if (!employee_id.success) return { success: false, error: employee_id.error }

//         const bank_code = await this.typeResolver.findIdAndModifierByType(LeaveTypes.HOLIDAY);
//         const dates = normalizeDates(dto.dates);
//         if (!bank_code) throw new NotFoundException(`bank_code not found`);
//         if (!dates.length) throw new BadRequestException('Dates array must not be empty');

//         const created: LeaveRequestViewDto[] = [];

//         for (const iso_date of dates) {
//             const date = toDateOnly(iso_date);

//             const existing = await this.prisma.leaveRequests.findUnique({
//                 where: {
//                     leave_per_employee_date: {
//                         employee_id: employee_id.data,
//                         leave_type: LeaveTypes.HOLIDAY,
//                         date,
//                     },
//                 },
//                 select: { id: true },
//             });
//             if (existing) {
//                 throw new BadRequestException(`Holiday request already exists for ${iso_date}`);
//             }

//             const payable = await this.holidayService.calculateHolidayPay(email, date, bank_code.modifier);
//             if (!payable) return { success: false, error: `An error occured during calculation` };

//             const row = await this.prisma.leaveRequests.create({
//                 data: {
//                     employee_id: employee_id.data,
//                     bank_code_id: bank_code.id,
//                     leave_type: LeaveTypes.HOLIDAY,
//                     date,
//                     comment: dto.comment ?? '',
//                     requested_hours: dto.requested_hours ?? 8,
//                     payable_hours: payable,
//                     approval_status: dto.approval_status ?? LeaveApprovalStatus.PENDING,
//                 },
//                 select: leaveRequestsSelect,
//             });

//             const hours = Number(row.payable_hours ?? row.requested_hours ?? 0);
//             if (row.approval_status === LeaveApprovalStatus.APPROVED) {
//                 await this.leaveUtils.syncShift(email, employee_id.data, iso_date, hours, LeaveTypes.HOLIDAY, row.comment);
//             }

//             created.push({ ...mapRowToView(row), action: 'create' });
//         }

//         return { success: true, data: { action: 'create', leave_requests: created } };
//     }
// }

