import { Controller, Get, Post, Body, Param, Delete, UseGuards, Query } from '@nestjs/common';
import { CategoryService } from './category.service';
import { AuthAdminGuard } from 'src/auth/admin/authAdmin.guard';
import { Roles } from 'src/auth/role.decorator';
import { SUPERADMIN_ROLES } from 'src/shared/enum/admin-role.enum';
import { ApiBearerAuth, ApiBody, ApiTags } from '@nestjs/swagger';
import { CreateCategoryReqDto } from './dto/create-category-req.dto';
import { LANGUAGES } from 'src/shared/enum/languages.enum';

@Controller('category')
@ApiTags('Category')
export class CategoryController {
  constructor(private readonly categoryService: CategoryService) {}

  @UseGuards(AuthAdminGuard)
  @Roles(SUPERADMIN_ROLES)
  @ApiBearerAuth('jwt')
  @ApiBody({ type: CreateCategoryReqDto })
  @Post()
  create(@Body() createCategoryDto: CreateCategoryReqDto) {
    this.categoryService.create(createCategoryDto);
    return { message: 'Category created successfully' };
  }

  @Get('')
  findAll(@Query('lang') lang: LANGUAGES) {
    return this.categoryService.findAll(lang);
  }

  @UseGuards(AuthAdminGuard)
  @Roles(SUPERADMIN_ROLES)
  @ApiBearerAuth('jwt')
  @Delete(':id')
  remove(@Param('id') id: string) {
    this.categoryService.remove(+id);
    return { message: 'Category deleted successfully' };
  }
}
