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 { StateService } from "./state.service"
import { CreateStateDto } from "../dto/create-state.dto"
import { FindAllStateDto } from "../dto/find-all-state.dto"
import { UpdateStateDto } from "../dto/update-state.dto"

@Controller("state")
@ApiTags("State")
@UseGuards(AuthGuardMiddleware)
@ApiBearerAuth("access-token")
export class StateController {
  constructor(private readonly stateService: StateService) {}

  @Post()
  @ApiBody({ type: CreateStateDto })
  async createState(@Body() createStateDto: CreateStateDto) {
    return await this.stateService.createstate(createStateDto)
  }

  @Get()
  async findAllStates(@Query() findAllStateDto: FindAllStateDto) {
    return this.stateService.findAllstate(findAllStateDto)
  }

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

  @Patch(":id")
  @ApiBody({ type: UpdateStateDto })
  async updateState(
    @Param("id") id: number,
    @Body() updateStateDto: UpdateStateDto,
  ) {
    return await this.stateService.updateState(id, updateStateDto)
  }

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

  @Get("country-states/:country_id")
  async getStatesByCountry(@Param("country_id") country_id: number) {
    return this.stateService.getStatesByCountry(Number(country_id))
  }
}
