import { Body, Controller, Get, HttpCode, HttpStatus, Param, Post } from '@nestjs/common';
import { RolesService } from './roles.service';
import { Roles } from 'src/roles/roles.decorator';
import { ERole } from './roles.service';
import { AllDescriptionsDto } from './dto/all-descriptions.dto';

@Controller('role')
export class RolesController {
  constructor(
    private rolesService: RolesService,
  ) {}

  // Get member roles (for member admin)
  @Get('descriptions')
  @Roles(ERole.MemberAdministrator)
  @HttpCode(HttpStatus.OK)
  async descriptions() {
    const data = await this.rolesService.findDescriptions();
    return { data };
  }

  // Get all available roles (for ipw admin)
  @Post('all-descriptions')
  @Roles(ERole.SystemDeveloper, ERole.IPWAdministrator)
  @HttpCode(HttpStatus.OK)
  async allDescriptions(
    @Body() body: AllDescriptionsDto
  ) {
    const data = await this.rolesService.findDescriptions({ user_class_id: body.user_class_id });
    return { data };
  }

  // TODO: member admins will need to use this route too
  // that said, they should only have access to a limited submit
  // the users with user_class_id 2 within their assigned orgs?
  // get roles for a specific user
  // should be a new route, memberRoles
  @Get('user/:id')
  @Roles(ERole.SystemDeveloper, ERole.IPWAdministrator)
  @HttpCode(HttpStatus.OK)
  async userRoles(
    @Param('id') user_id: string
  ) {
    const data = await this.rolesService.findUserRoleDescriptions(parseInt(user_id));
    return { data };
  }
}