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

@ApiTags('recruiter_verification')
@ApiBearerAuth('access-token')
@Controller('recruiter_verification')
export class RecruiterVerificationController {
  constructor(
    private readonly recruiterVerificationService: RecruiterVerificationService,
  ) {}

  @Public()
  @Post('create')
  @ApiOperation({ summary: 'Create Verification Request' })
  @ApiBody({
    schema: {
      type: 'object',
      properties: {
        user_id: { type: 'number' },
        company_id: { type: 'number' },
        cin_number: { type: 'string' },
        gst_number: { type: 'string' },
        is_franchise_added: { type: 'boolean' },
        franchise_id: { type: 'number' },
      },
      required: ['user_id', 'company_id', 'is_franchise_added'],
    },
  })
  async createVerificationRequest(
    @Body()
    data: {
      user_id: number;
      company_id: number;
      cin_number?: string;
      gst_number?: string;
      is_franchise_added: boolean;
      franchise_id?: number;
    },
  ) {
    return this.recruiterVerificationService.createVerificationRequest(data);
  }

  @Public()
  @Get('pending')
  @ApiOperation({ summary: 'Get Pending Verifications' })
  @ApiQuery({ name: 'page', required: false, type: String })
  @ApiQuery({ name: 'limit', required: false, type: String })
  async getPendingVerifications(
    @Query('page') page: string = '1',
    @Query('limit') limit: string = '10',
  ) {
    return this.recruiterVerificationService.getPendingVerifications(
      parseInt(page),
      parseInt(limit),
    );
  }

  @Public()
  @Get('stats')
  @ApiOperation({ summary: 'Get verification stats' })
  async getVerificationStats() {
    return this.recruiterVerificationService.getVerificationStats();
  }

  @Public()
  @Get('debug/all')
  @ApiOperation({ summary: 'Get all verifications (debug)' })
  async getAllVerifications() {
    return this.recruiterVerificationService.getAllVerifications();
  }

  @Public()
  @Get(':id')
  @ApiOperation({ summary: 'Get verification by ID' })
  @ApiParam({ name: 'id', type: String })
  async getVerificationById(@Param('id') id: string) {
    return this.recruiterVerificationService.getVerificationById(parseInt(id));
  }

  @Public()
  @Put(':id/approve')
  @ApiOperation({ summary: 'Approve Verification' })
  @ApiParam({ name: 'id', type: String })
  @ApiBody({
    schema: {
      type: 'object',
      properties: { adminId: { type: 'number' }, remarks: { type: 'string' } },
      required: ['adminId'],
    },
  })
  async approveVerification(
    @Param('id') id: string,
    @Body() data: { adminId: number; remarks?: string },
  ) {
    return this.recruiterVerificationService.approveVerification(
      parseInt(id),
      data.adminId,
      data.remarks,
    );
  }

  @Public()
  @Put(':id/reject')
  @ApiOperation({ summary: 'Reject Verification' })
  @ApiParam({ name: 'id', type: String })
  @ApiBody({
    schema: {
      type: 'object',
      properties: { adminId: { type: 'number' }, remarks: { type: 'string' } },
      required: ['adminId', 'remarks'],
    },
  })
  async rejectVerification(
    @Param('id') id: string,
    @Body() data: { adminId: number; remarks: string },
  ) {
    return this.recruiterVerificationService.rejectVerification(
      parseInt(id),
      data.adminId,
      data.remarks,
    );
  }
}
