import { ApiProperty } from '@nestjs/swagger';
import { IsEmail, IsString, MinLength, IsIn } from 'class-validator';

export class AuthenticatedUserDTO {
  @ApiProperty()
  userId!: string;
  @ApiProperty()
  email!: string;
  @ApiProperty()
  displayName!: string;
  @ApiProperty({ required: false })
  primaryDriverId?: string;
  @ApiProperty({ required: false, nullable: true })
  avatarUrl?: string | null;
}

export class AuthSessionDTO {
  @ApiProperty()
  token!: string;
  @ApiProperty()
  user!: AuthenticatedUserDTO;
}

export class SignupParamsDTO {
  @ApiProperty()
  email!: string;
  @ApiProperty()
  password!: string;
  @ApiProperty()
  displayName!: string;
  @ApiProperty({ required: false })
  iracingCustomerId?: string;
  @ApiProperty({ required: false })
  primaryDriverId?: string;
  @ApiProperty({ required: false, nullable: true })
  avatarUrl?: string | null;
}

export class LoginParamsDTO {
  @ApiProperty()
  email!: string;
  @ApiProperty()
  password!: string;
}

export class IracingAuthRedirectResultDTO {
  @ApiProperty()
  redirectUrl!: string;
  @ApiProperty()
  state!: string;
}

export class LoginWithIracingCallbackParamsDTO {
  @ApiProperty()
  code!: string;
  @ApiProperty()
  state!: string;
  @ApiProperty({ required: false })
  returnTo?: string;
}

export class ForgotPasswordDTO {
  @ApiProperty()
  @IsEmail()
  email!: string;
}

export class ResetPasswordDTO {
  @ApiProperty()
  @IsString()
  token!: string;

  @ApiProperty()
  @IsString()
  @MinLength(8)
  newPassword!: string;
}

export class DemoLoginDTO {
  @ApiProperty({ enum: ['driver', 'sponsor', 'league-owner', 'league-steward', 'league-admin', 'system-owner', 'super-admin'] })
  @IsString()
  @IsIn(['driver', 'sponsor', 'league-owner', 'league-steward', 'league-admin', 'system-owner', 'super-admin'])
  role!: 'driver' | 'sponsor' | 'league-owner' | 'league-steward' | 'league-admin' | 'system-owner' | 'super-admin';
}
