import { Controller, Get, Param, Post, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { successfulResult } from '../../utils';
import { JwtAuthGuard } from '../auth/jwt/jwt.guard';
import { InsuranceService } from './insurance.service';
import { User } from '../../utils/decorators/user.decorator';
import { UserEntity } from '../user/entities/user.entity';

@ApiTags('Insurance')
@Controller('insurances')
export class InsuranceController {
  constructor(private insuranceService: InsuranceService) {}

  // /**
  //  * -------------------------------------------------------
  //  * POST /insurances/third-party-inquiry/crawler
  //  */
  // @Post('third-party-inquiry/crawler')
  // async crawlerThirdPartyInquiry() {
  //   const output =
  //     await this.insuranceService.handleThirdPartyInquiryForValidCars();
  //   return successfulResult(['Done'], output);
  // }

  /**
   * -------------------------------------------------------
   * GET /insurances/third-party/remain-days/1/me
   */
  @Get('/third-party/remain-days/:carId/me')
  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard)
  async getRemainDaysToNewThirdParty(
    @Param('carId') carId: number,
    @User() user: UserEntity,
  ) {
    const data = await this.insuranceService.getRemainDaysToNewThirdParty(
      carId,
      user,
    );
    return successfulResult([], data);
  }

  /**
   * -------------------------------------------------------
   * GET /insurances/third-party-inquiry/1/me
   */
  @Get('third-party-inquiry/:carId/me')
  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard)
  async getThirdPartyInquiry(
    @Param('carId') carId: number,
    @User() user: UserEntity,
  ) {
    const data = await this.insuranceService.getThirdPartyInquiry(carId, user);
    return successfulResult([], data);
  }
}
