import {
  Controller,
  Get,
  Post,
  Body,
  Param,
  Delete,
  Put,
  Query,
} from "@nestjs/common"
import { RoleService } from "./role.service"
import { CreateRoleDto } from "../dto/create-role.dto"
import { ApiBody, ApiQuery, ApiTags } from "@nestjs/swagger"
import { UpdateRoleDto } from "../dto/update-role.dto"
import { FindAllRolesDto } from "../dto/find-all-roles.dto"

@Controller("roles")
@ApiTags("Role")
export class RoleController {
  constructor(private readonly roleService: RoleService) {}

  // Create a new role
  @Post("create")
  @ApiBody({ type: CreateRoleDto })
  async createRole(@Body() createRoleDto: CreateRoleDto) {
    const role = await this.roleService.createRole(createRoleDto)
    return role
  }

  @Get("list")
  async findAllRoles(@Query() roleDto: FindAllRolesDto) {
    return this.roleService.findAllRoles(roleDto)
  }

  // Get a specific role by ID
  @Get("list/:id")
  async findOne(@Param("id") id: number) {
    return await this.roleService.findOneRole(id)
  }

  // Update a role by ID
  @Put("update/:id")
  @ApiBody({ type: UpdateRoleDto })
  async update(@Param("id") id: number, @Body() updateData: UpdateRoleDto) {
    return await this.roleService.updateRole(id, updateData)
  }

  // Delete a role by ID
  @Delete("delete/:id")
  async remove(@Param("id") id: number) {
    return await this.roleService.remove(id)
  }
  // Change role status
  @Put("status/:id")
  @ApiBody({ type: UpdateRoleDto })
  async changeStatus(@Param("id") id: number, @Body("status") status: number) {
    return await this.roleService.changeRoleStatus(id, status)
  }

  @Get("dropdown")
  @ApiQuery({
    name: "exclude_id",
    required: false,
    type: String,
    description: "Enter the id to be excluded from the dropdown",
  })
  async rolesDropdown(@Query("exclude_id") excludeId?: string) {
    return await this.roleService.rolesDropdown(excludeId)
  }
}
