import { Controller, Get, Query, Body, Post, Patch } from "@nestjs/common";
import { Modules as ModulesEnum } from "prisma/postgres/generated/prisma/client/postgres/client";
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
import { Access } from "src/common/decorators/module-access.decorators";
import { Result } from "src/common/errors/result-error.factory";
import { EmployeeDetailedDto, EmployeeDetailedUpsertDto } from "src/identity-and-account/employees/employee-detailed.dto";
import { EmployeesGetService } from "src/identity-and-account/employees/services/employees-get.service";
import { EmployeesCreateService } from "src/identity-and-account/employees/services/employees-create.service";
import { EmployeesUpdateService } from "src/identity-and-account/employees/services/employees-update.service";

@Controller('employees')
export class EmployeesController {
	constructor(
		private readonly getService: EmployeesGetService,
		private readonly createService: EmployeesCreateService,
		private readonly updateService: EmployeesUpdateService,
	) { }

	@Get('personal-profile')
	@ModuleAccessAllowed(ModulesEnum.personal_profile)
	async findOwnProfile(@Access('email') email: string): Promise<Result<Partial<EmployeeDetailedDto>, string>> {
		return await this.getService.findOwnProfile(email);
	}

	@Get('profile')
	@ModuleAccessAllowed(ModulesEnum.personal_profile)
	async findProfile(@Access('email') email: string, @Query('employee_email') employee_email?: string,
	): Promise<Result<Partial<EmployeeDetailedDto>, string>> {
		return await this.getService.findOneDetailedProfile(email, employee_email);
	}

	@Get('employee-list')
	@ModuleAccessAllowed(ModulesEnum.employee_list)
	async findListEmployees(): Promise<Result<Partial<EmployeeDetailedDto>[], string>> {
		return this.getService.findListEmployees();
	}

	@Post('create')
	@ModuleAccessAllowed(ModulesEnum.employee_management)
	async createEmployee(@Body() dto: EmployeeDetailedUpsertDto): Promise<Result<boolean, string>> {
		return await this.createService.createEmployee(dto);
	}

	@Patch('update')
	@ModuleAccessAllowed(ModulesEnum.employee_management)
	async updateEmployee(@Body() dto:EmployeeDetailedUpsertDto){
		return await this.updateService.updateEmployee(dto);
	}
}
