import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Param,
  Body,
  HttpException,
  HttpStatus,
} from '@nestjs/common';
import { CompanyRecruitersService } from '../company_recruiters/company_recruiters.service';
import { CompanyRecruiters } from './entities/company_recruiters.entity';
import {
  ApiBearerAuth,
  ApiTags,
  ApiBody,
  ApiParam,
  ApiQuery,
  ApiOperation,
} from '@nestjs/swagger';
import { Public } from '../auth/public.decorator';

@ApiTags('company_recruiters')
@ApiBearerAuth('access-token')
@Controller('company_recruiters')
export class CompanyRecruitersController {
  constructor(
    private readonly companyRecruitersService: CompanyRecruitersService,
  ) {}

  @Public()
  @Get()
  @ApiOperation({ summary: 'Get All Company Recruiters' })
  async findAll(): Promise<CompanyRecruiters[]> {
    try {
      return await this.companyRecruitersService.findAll();
    } catch (error) {
      throw new HttpException(
        'Failed to fetch records',
        HttpStatus.INTERNAL_SERVER_ERROR,
      );
    }
  }

  @Public()
  @Get(':id')
  @ApiOperation({ summary: 'Get Company Recruiter by ID' })
  @ApiParam({ name: 'id', type: Number })
  async findOne(@Param('id') id: number): Promise<CompanyRecruiters> {
    try {
      return await this.companyRecruitersService.findOne(+id);
    } catch (error) {
      throw new HttpException(
        error.message,
        error.status || HttpStatus.NOT_FOUND,
      );
    }
  }

  @Public()
  @Post()
  @ApiOperation({ summary: 'Create Company Recruiter' })
  @ApiBody({ schema: { type: 'object', description: 'Recruiter data' } })
  async create(
    @Body() data: Partial<CompanyRecruiters>,
  ): Promise<CompanyRecruiters> {
    try {
      return await this.companyRecruitersService.create(data);
    } catch (error) {
      throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
    }
  }

  @Public()
  @Put(':id')
  @ApiOperation({ summary: 'Update Company Recruiter' })
  @ApiParam({ name: 'id', type: Number })
  @ApiBody({ schema: { type: 'object', description: 'Recruiter data' } })
  async update(
    @Param('id') id: number,
    @Body() data: Partial<CompanyRecruiters>,
  ): Promise<CompanyRecruiters> {
    try {
      return await this.companyRecruitersService.update(+id, data);
    } catch (error) {
      throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
    }
  }

  @Public()
  @Delete(':id')
  @ApiOperation({ summary: 'Delete Company Recruiter' })
  @ApiParam({ name: 'id', type: Number })
  async remove(@Param('id') id: number): Promise<{ message: string }> {
    try {
      return await this.companyRecruitersService.remove(+id);
    } catch (error) {
      throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
    }
  }
}
