import { User } from '@/entities/user.entity';
import CoreController from '@/system/core/core-controller';
import { SystemLang } from '@/system/lang/system.lang';
import { Body, Controller, Param, Post, Put, Req } from '@nestjs/common';
import { HasFeature } from '../authorization/decorators/has-feature.decorator';
import { CreateUserDto } from './dtos/create-user.dto';
import { UsersService } from './users.service';
import { UpdateUserDto } from './dtos/update-user.dto';
import { Request } from 'express';

@Controller('admin/users')
@HasFeature({
  name: SystemLang.getCustomText({
    vi: 'Quản lý người dùng hoặc nhân viên',
    en: 'Manage Users',
  }),
  group_key: 'users',
  description: SystemLang.getCustomText({
    vi: 'Danh sách, tạo, sửa, xóa người dùng hoặc nhân viên',
    en: 'List, create, update, and delete admin accounts',
  }),
})
export class UsersController extends CoreController<User, UsersService> {
  constructor(protected readonly service: UsersService) {
    super(service);
  }

  @Post()
  async create(@Body() dto: CreateUserDto) {
    return await this.service.create(dto);
  }

  @Put(':id')
  async update(
    @Body() data: UpdateUserDto,
    @Param('id') id: User['id'],
    @Req() resquest: Request,
  ) {
    return await this.service.updateWithoutValidation(id, data, resquest);
  }
}
