import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Param,
  Body,
} from '@nestjs/common';
import { JobPerksService } from './job_perks.service';
import { Public } from '../auth/public.decorator';
import {
  ApiBearerAuth,
  ApiTags,
  ApiOperation,
  ApiBody,
  ApiParam,
} from '@nestjs/swagger';

@ApiTags('job_perks')
@ApiBearerAuth('access-token')
@Controller('job_perks')
export class JobPerksController {
  constructor(private readonly jobPerksService: JobPerksService) {}

  @Public()
  @Get('job/:jobId')
  @ApiOperation({ summary: 'Find perks by job ID' })
  @ApiParam({ name: 'jobId', type: Number })
  findByJobId(@Param('jobId') jobId: number) {
    return this.jobPerksService.findByJobId(jobId);
  }

  @Public()
  @Post('add_perk')
  @ApiOperation({ summary: 'Add perk to job' })
  @ApiBody({
    schema: {
      type: 'object',
      properties: { jobId: { type: 'number' }, perkId: { type: 'number' } },
    },
  })
  addPerkToJob(@Body() data: { jobId: number; perkId: number }) {
    return this.jobPerksService.addPerkToJob(data.jobId, data.perkId);
  }

  @Public()
  @Post('add_custom_perk')
  @ApiOperation({ summary: 'Add custom perk to job' })
  @ApiBody({
    schema: {
      type: 'object',
      properties: { jobId: { type: 'number' }, customName: { type: 'string' } },
    },
  })
  addCustomPerkToJob(@Body() data: { jobId: number; customName: string }) {
    return this.jobPerksService.addCustomPerkToJob(data.jobId, data.customName);
  }

  @Public()
  @Delete('remove_perk')
  @ApiOperation({ summary: 'Remove perk from job' })
  @ApiBody({
    schema: {
      type: 'object',
      properties: { jobId: { type: 'number' }, perkId: { type: 'number' } },
    },
  })
  removePerkFromJob(@Body() data: { jobId: number; perkId: number }) {
    return this.jobPerksService.removePerkFromJob(data.jobId, data.perkId);
  }

  @Public()
  @Delete('remove_custom_perk')
  @ApiOperation({ summary: 'Remove custom perk from job' })
  @ApiBody({
    schema: {
      type: 'object',
      properties: { jobId: { type: 'number' }, customName: { type: 'string' } },
    },
  })
  removeCustomPerkFromJob(@Body() data: { jobId: number; customName: string }) {
    return this.jobPerksService.removeCustomPerkFromJob(
      data.jobId,
      data.customName,
    );
  }

  @Public()
  @Put('update_job_perks')
  @ApiOperation({ summary: 'Update job perks' })
  @ApiBody({
    schema: {
      type: 'object',
      properties: {
        jobId: { type: 'number' },
        perkIds: { type: 'array', items: { type: 'number' } },
        customPerks: { type: 'array', items: { type: 'string' } },
      },
    },
  })
  updateJobPerks(
    @Body() data: { jobId: number; perkIds: number[]; customPerks: string[] },
  ) {
    return this.jobPerksService.updateJobPerks(
      data.jobId,
      data.perkIds,
      data.customPerks,
    );
  }
}
