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 { CityService } from "./city.service"
import { CreateCityDto } from "../dto/create-city.dto"
import { FindAllCityDto } from "../dto/find-all-city.dto"
import { UpdateCityDto } from "../dto/update-city.dto"
import { UpsertLocationDto } from "../dto/upsert-location.dto"

@Controller("city")
@ApiTags("City")
@UseGuards(AuthGuardMiddleware)
@ApiBearerAuth("access-token")
export class CityController {
  constructor(private readonly cityService: CityService) {}

  @Post()
  @ApiBody({ type: CreateCityDto })
  async createCity(@Body() createCityDto: CreateCityDto) {
    return await this.cityService.createCity(createCityDto)
  }

  @Get()
  async findAllCities(@Query() userFilterDto: FindAllCityDto) {
    return this.cityService.findAllCities(userFilterDto)
  }

  @Get("dropdown")
  async getCityDetails() {
    return this.cityService.getCityDropdown()
  }

  @Get(":id")
  async findOneCity(@Param("id") id: number) {
    return await this.cityService.findOneCity(id)
  }

  @Patch(":id")
  @ApiBody({ type: UpdateCityDto })
  async updateCity(
    @Param("id") id: number,
    @Body() updateCityDto: UpdateCityDto,
  ) {
    return await this.cityService.updateCity(id, updateCityDto)
  }

  @Delete(":id")
  async removeCity(@Param("id") id: number) {
    return await this.cityService.remove(id)
  }

  @Get("details/:id")
  async getCityDropdownDetails(@Param("id") id: number) {
    return this.cityService.getCityDetailsForDropdown(id)
  }

  @Post("location")
  async upsertLocation(@Body() upsertLocationDto: UpsertLocationDto) {
    return this.cityService.upsertLocation(upsertLocationDto)
  }
}
