import { IsNotEmpty, IsArray, IsEnum, IsOptional, IsString, IsDateString, ArrayMinSize, IsInt, IsPositive, ArrayUnique } from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { AccessScopeEnum } from 'src/common/enum/access-scope.enum';
import { Type } from 'class-transformer';

/**
 * DTO for adding users to program access map
 */
export class AddProgramAccessUsersDto {
  @ApiProperty({
    description: 'Array of user IDs to grant access',
    type: [Number],
    example: [101, 205, 321],
  })
  @IsNotEmpty()
  @IsArray()
  @ArrayMinSize(1)
  @ArrayUnique()
  @IsInt({ each: true })
  @IsPositive({ each: true })
  @Type(() => Number)
  userIds: number[];

  @ApiProperty({
    description: 'Access scope for the users',
    enum: AccessScopeEnum,
    default: AccessScopeEnum.VIEW_AND_REGISTER,
    example: AccessScopeEnum.VIEW_AND_REGISTER,
  })
  @IsEnum(AccessScopeEnum)
  @IsOptional()
  accessScope?: AccessScopeEnum = AccessScopeEnum.VIEW_AND_REGISTER;

  @ApiPropertyOptional({
    description: 'When the access becomes effective (ISO 8601 format)',
    example: '2026-03-28T00:00:00.000Z',
  })
  @IsOptional()
  @IsDateString()
  effectiveFrom?: string;

  @ApiPropertyOptional({
    description: 'When the access expires (ISO 8601 format)',
    example: null,
  })
  @IsOptional()
  @IsDateString()
  effectiveTill?: string;

  @ApiPropertyOptional({
    description: 'Reason for granting access',
    example: 'Internal batch publish',
  })
  @IsOptional()
  @IsString()
  reason?: string;

  @ApiPropertyOptional({
    description: 'Additional metadata',
    example: { source: 'admin_panel', batch_id: '123' },
  })
  @IsOptional()
  meta?: Record<string, any>;
}
