import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
  ArrayUnique,
  IsArray,
  IsInt,
  IsOptional,
  IsPositive,
  IsString,
  MaxLength,
  MinLength,
} from 'class-validator';

export class CreateRoleDto {
  @ApiProperty({ example: 'admin' })
  @IsString()
  @MinLength(1)
  @MaxLength(50)
  name!: string;

  @ApiPropertyOptional({
    example: 'web',
    default: 'web',
    description: 'Auth guard this role applies to',
  })
  @IsOptional()
  @IsString()
  @MaxLength(50)
  guardName?: string;

  @ApiPropertyOptional({
    type: [Number],
    example: [1, 2, 3],
    description:
      'IDs of permissions to grant the role. On update this replaces the current set (empty array clears all).',
  })
  @IsOptional()
  @IsArray()
  @ArrayUnique()
  @IsInt({ each: true })
  @IsPositive({ each: true })
  permissionIds?: number[];
}
