import {
  Controller,
  Get,
  Post,
  Body,
  Param,
  Delete,
  UseGuards,
  Query,
  Patch,
} from "@nestjs/common"
import { ApiBearerAuth, ApiBody, ApiTags } from "@nestjs/swagger"
import { AuthGuardMiddleware } from "src/middleware/auth-guard.middleware"
import { CountryService } from "./country.service"
import { CreateCountryDto } from "../dto/create-country.dto"
import { FindAllCountryDto } from "../dto/find-all-country.dto"
import { UpdateCountryDto } from "../dto/update-country.dto"

@Controller("country")
@ApiTags("Country")
@UseGuards(AuthGuardMiddleware)
@ApiBearerAuth("access-token")
export class CountryController {
  constructor(private readonly countryService: CountryService) {}

  // Create a new country
  @Post("create")
  @ApiBody({ type: CreateCountryDto })
  async createCountry(@Body() createCountryDto: CreateCountryDto) {
    return await this.countryService.createCountry(createCountryDto)
  }

  @Get("list")
  async findAllCountries(@Query() userFilterDto: FindAllCountryDto) {
    return this.countryService.findAllCountries(userFilterDto)
  }

  // Get a specific country by ID
  @Get("list/:id")
  async findOne(@Param("id") id: number) {
    return await this.countryService.findOneCountry(id)
  }

  // Update a country by ID
  @Patch("update/:id")
  @ApiBody({ type: UpdateCountryDto })
  async update(@Param("id") id: number, @Body() updateData: UpdateCountryDto) {
    return await this.countryService.updateCountry(id, updateData)
  }

  // Delete a country by ID
  @Delete("delete/:id")
  async remove(@Param("id") id: number) {
    return await this.countryService.remove(id)
  }

  // Get dropdown list of countries
  @Get("dropdown")
  async getDropdownCountries() {
    return await this.countryService.getDropdownCountries()
  }
}
