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 { ModuleService } from "./module.service"
import { CreateModuleDto } from "../dto/create-module.dto"
import { UpdateModuleDto } from "../dto/update-module.dto"
import { FindAllModuleDto } from "../dto/find-all-module.dto"

@Controller("module")
@ApiTags("Module")
@UseGuards(AuthGuardMiddleware)
@ApiBearerAuth("access-token")
export class ModuleController {
  constructor(private readonly moduleService: ModuleService) {}

  // Create a new module
  @Post()
  @ApiBody({ type: CreateModuleDto })
  async createModule(@Body() createModuleDto: CreateModuleDto) {
    return await this.moduleService.createModule(createModuleDto)
  }

  // List modules with filters/pagination/sorting
  @Get()
  async findAllModules(@Query() query: FindAllModuleDto) {
    return await this.moduleService.findAllModules(query)
  }

  // Get specific module by ID
  @Get(":id")
  async findOne(@Param("id") id: number) {
    return await this.moduleService.findOneModule(id)
  }

  // Update module by ID
  @Patch(":id")
  @ApiBody({ type: UpdateModuleDto })
  async update(@Param("id") id: number, @Body() updateData: UpdateModuleDto) {
    return await this.moduleService.updateModule(id, updateData)
  }

  // Delete module by ID
  @Delete(":id")
  async remove(@Param("id") id: number) {
    return await this.moduleService.remove(id)
  }

  // Get dropdown list of modules
  @Get("dropdown")
  async getDropdownModules() {
    return await this.moduleService.getDropdownModules()
  }

  @Post("by-business-vertical")
  getModulesByBusinessVerticals(@Body() body: { ids: number[] }) {
    return this.moduleService.getModulesByBusinessVerticalIds(body.ids)
  }
}
