import { Type } from 'class-transformer';
import { IsArray, IsBoolean, IsIn, IsNotEmpty, IsOptional, IsString, MaxLength, ValidateNested } from 'class-validator';
import { CRM_MODULES, type CrmModule } from '../roles.constants';

export class RolePermissionDto {
  @IsString()
  @IsIn(CRM_MODULES)
  module!: CrmModule;

  @IsBoolean()
  canCreate!: boolean;

  @IsBoolean()
  canRead!: boolean;

  @IsBoolean()
  canUpdate!: boolean;

  @IsBoolean()
  canDelete!: boolean;

  @IsBoolean()
  canExport!: boolean;
}

export class CreateRoleDto {
  @IsString()
  @IsNotEmpty()
  @MaxLength(100)
  name!: string;

  @IsString()
  @IsOptional()
  @MaxLength(255)
  description?: string;

  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => RolePermissionDto)
  permissions!: RolePermissionDto[];
}
