import {
  IsArray,
  IsEmail,
  IsEnum,
  IsOptional,
  IsString,
  ArrayNotEmpty,
} from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { UserRole } from '@prisma/client';

export class PasswordLoginDto {
  @ApiProperty({ example: 'admin@yourstore.com' })
  @IsEmail()
  email!: string;

  @ApiProperty({ example: 'StrongPass@123' })
  @IsString()
  password!: string;

  /**
   * Optional allow-list of roles this login is intended for.
   * If provided, login is allowed only when the user's role is included here.
   */
  @ApiPropertyOptional({
    example: ['ADMIN', 'SUBADMIN'],
    description:
      'Optional allow-list of roles permitted for this login attempt',
    isArray: true,
  })
  @IsOptional()
  @IsArray()
  @ArrayNotEmpty()
  @IsEnum(UserRole, { each: true })
  roles?: UserRole[];
}
