import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Query,
  UseGuards,
} from "@nestjs/common"
import { PlansService } from "./plans.service"
import { CreatePlanDto } from "../dto/create-plan.dto"
import { UpdatePlanDto } from "../dto/update-plan.dto"
import { ApiBearerAuth, ApiQuery, ApiTags } from "@nestjs/swagger"
import { AuthGuardMiddleware } from "src/middleware/auth-guard.middleware"

@ApiTags("Plan")
@UseGuards(AuthGuardMiddleware)
@ApiBearerAuth("access-token")
@Controller("plans")
export class PlansController {
  constructor(private readonly plansService: PlansService) {}

  @Post()
  create(@Body() createPlanDto: CreatePlanDto) {
    return this.plansService.create(createPlanDto)
  }

  @Get()
  @ApiQuery({
    name: "search",
    required: false,
    description: "Search keyword to filter plans by name or description",
    example: "premium",
  })
  findAll(@Query("search") search?: string) {
    return this.plansService.findAll(search)
  }

  @Get(":id")
  findOne(@Param("id") id: string) {
    return this.plansService.findOne(+id)
  }

  @Patch(":id")
  update(@Param("id") id: string, @Body() updatePlanDto: UpdatePlanDto) {
    return this.plansService.update(+id, updatePlanDto)
  }

  @Delete(":id")
  remove(@Param("id") id: string) {
    return this.plansService.remove(+id)
  }
}
