import { ApiProperty } from '@nestjs/swagger';
import { UploadSessionStatus } from '@prisma/client';
import { IsInt, IsString, IsUUID, Matches, Max, Min } from 'class-validator';

export class UploadPrepareRequestDto {
  @ApiProperty({ format: 'uuid' })
  @IsUUID()
  deviceId!: string;

  @ApiProperty({
    example:
      'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
  })
  @Matches(/^[a-f0-9]{64}$/)
  sha256!: string;

  @ApiProperty({ example: 'track.mp3' })
  @IsString()
  originalFilename!: string;

  @ApiProperty({ example: 10485760 })
  @IsInt()
  @Min(1)
  @Max(Number.MAX_SAFE_INTEGER)
  sizeBytes!: number;
}

export class UploadPrepareResponseDto {
  @ApiProperty({ enum: ['exists', 'upload_required'] })
  status!: 'exists' | 'upload_required';

  @ApiProperty({ required: false, format: 'uuid' })
  uploadId?: string;

  @ApiProperty({ required: false, example: 0 })
  nextOffset?: number;
}

export class UploadSessionStatusResponseDto {
  @ApiProperty({ format: 'uuid' })
  uploadId!: string;

  @ApiProperty({ enum: UploadSessionStatus })
  status!: UploadSessionStatus;

  @ApiProperty({ example: 0 })
  receivedBytes!: string;

  @ApiProperty({ example: 10485760 })
  expectedSizeBytes!: string;

  @ApiProperty({ example: 0 })
  nextOffset!: string;
}

export class UploadFinalizeResponseDto {
  @ApiProperty({ example: 501 })
  statusCode!: number;

  @ApiProperty({ example: 'Upload finalization is not implemented yet.' })
  message!: string;
}
