import { Body, Controller, Get, Param, ParseBoolPipe, ParseIntPipe, Patch, Query } from "@nestjs/common";
import { GetTimesheetsOverviewService } from "src/time-and-attendance/timesheets/services/timesheet-employee-overview.service";
import { TimesheetApprovalService } from "src/time-and-attendance/timesheets/services/timesheet-approval.service";
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
import { Modules as ModulesEnum } from "prisma/postgres/generated/prisma/client/postgres/client";
import { Access } from "src/common/decorators/module-access.decorators";


@Controller('timesheets')
export class TimesheetController {
    constructor(
        private readonly timesheetOverview: GetTimesheetsOverviewService,
        private readonly approvalService: TimesheetApprovalService,
    ) { }

    @Get(':year/:period_number')
    @ModuleAccessAllowed(ModulesEnum.timesheets)
    getTimesheetByPayPeriod(
        @Access('email') email: string,
        @Param('year', ParseIntPipe) year: number,
        @Param('period_number', ParseIntPipe) period_number: number,
        @Query('employee_email') employee_email?: string,
    ) {
        return this.timesheetOverview.getTimesheetsForEmployeeByPeriod(email, year, period_number, employee_email);
    }

    @Patch('timesheet-approval')
    @ModuleAccessAllowed(ModulesEnum.timesheets_approval)
    approveTimesheet(
        @Body('timesheet_id', ParseIntPipe) timesheet_id: number,
        @Body('is_approved', ParseBoolPipe) is_approved: boolean,
    ) {
        return this.approvalService.approveTimesheetById(timesheet_id, is_approved);
    }
}

