import { Body, Controller, Get, Param, Post, Put } from '@nestjs/common';
import {
  FunctionPermission,
  HasFeature,
} from '../authorization/decorators/has-feature.decorator';
import { SystemLang } from '@/system/lang/system.lang';
import { RolesService } from './roles.service';
import CoreController from '@/system/core/core-controller';
import { Role } from '@/entities/role.entity';
import { ExtendsDto } from './dtos/extends.dto';
import { CreateRoleDto } from './dtos/create-role.dto';

@Controller('admin/roles')
@HasFeature({
  name: SystemLang.getCustomText({
    vi: 'Quản lý vai trò',
    en: 'Role Management',
  }),
  group_key: 'roles',
  description: SystemLang.getCustomText({
    vi: 'Danh sách, tạo, sửa, xóa vai trò và phân quyền',
    en: 'List, create, update, and delete roles and permissions',
  }),
})
export class RolesController extends CoreController<Role, RolesService> {
  constructor(protected readonly service: RolesService) {
    super(service);
  }

  @Post('extends/:id')
  @HasFeature({
    name: SystemLang.getCustomText({
      vi: 'Kế thừa vai trò',
      en: 'Extend Role',
    }),
    description: SystemLang.getCustomText({
      vi: 'Cho phép kế thừa quyền từ vai trò khác',
      en: 'Allows inheriting permissions from another role',
    }),
    function_permisstion: FunctionPermission.UPDATE,
  })
  async extends(@Body() data: ExtendsDto, @Param('id') id: Role['id']) {
    return await this.service.extends(id, data);
  }

  @Post()
  async create(@Body() data: CreateRoleDto): Promise<any> {
    return await this.service.create(data);
  }
}
