import { Resource } from '@/entities/resource.entity';
import { Role } from '@/entities/role.entity';
import CoreController from '@/system/core/core-controller';
import { SystemLang } from '@/system/lang/system.lang';
import { Body, Controller, Get, Param, Post, Put } from '@nestjs/common';
import { Paginate, PaginateQuery } from 'nestjs-paginate';
import { HasFeature } from '../authorization/decorators/has-feature.decorator';
import { CreateResourceRoleDto } from './dtos/create-resource-role.dto';
import { ResourceService } from './resource.service';

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

  @Get('role/:id')
  async resourceByRole(
    @Param('id') role_id: Role['id'],
    @Paginate() query: PaginateQuery,
  ) {
    return await this.service.resourceByRole(role_id, { ...query });
  }

  @Put('role/:id')
  async updateResouceRole(
    @Param('id') role_id: Role['id'],
    @Body() data: CreateResourceRoleDto,
  ) {
    return this.service.updateResouceRole(role_id, data);
  }
}
