import { Body, Controller, Get, Patch, Query } from "@nestjs/common";
import { PreferencesService } from "./preferences.service";
import { PreferencesDto } from "./preferences.dto";
import { Result } from "src/common/errors/result-error.factory";
import { Access } from "src/common/decorators/module-access.decorators";
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
import { Modules as ModulesEnum } from "prisma/postgres/generated/prisma/client/postgres/client";

@Controller('preferences')
export class PreferencesController {
    constructor(private readonly service: PreferencesService) { }

    @Patch('update')
    @ModuleAccessAllowed(ModulesEnum.personal_profile)
    async updatePreferences(@Access('email') email: string, @Body() payload: PreferencesDto
    ): Promise<Result<PreferencesDto, string>> {
        return this.service.updatePreferences(email, payload);
    }

    @Get()
    @ModuleAccessAllowed(ModulesEnum.personal_profile)
    async findPreferences(@Access('email') email: string, @Query() employee_email?: string) {
        return this.service.findPreferences(email, employee_email);
    }

}