import {
  IsString,
  IsOptional,
  IsBoolean,
  IsNumber,
  IsArray,
  IsObject,
  IsUUID,
  MaxLength,
  MinLength,
  Min,
} from 'class-validator';

// ============================================
// BUCKET DTOs
// ============================================

export class CreateBucketDto {
  @IsString()
  @MinLength(2)
  @MaxLength(100)
  name: string;

  @IsOptional()
  @IsString()
  description?: string;

  @IsOptional()
  @IsString()
  @MaxLength(20)
  bucketType?: string;

  @IsOptional()
  @IsString()
  @MaxLength(20)
  provider?: string;

  @IsOptional()
  @IsBoolean()
  isPublic?: boolean;

  @IsOptional()
  @IsNumber()
  @Min(0)
  maxSizeBytes?: number;

  @IsOptional()
  @IsNumber()
  @Min(0)
  maxFileSize?: number;

  @IsOptional()
  @IsArray()
  @IsString({ each: true })
  allowedMimeTypes?: string[];

  @IsOptional()
  @IsObject()
  retentionPolicy?: Record<string, any>;

  @IsOptional()
  @IsObject()
  providerConfig?: Record<string, any>;
}

export class UpdateBucketDto {
  @IsOptional()
  @IsString()
  @MaxLength(100)
  name?: string;

  @IsOptional()
  @IsString()
  description?: string;

  @IsOptional()
  @IsBoolean()
  isPublic?: boolean;

  @IsOptional()
  @IsNumber()
  @Min(0)
  maxSizeBytes?: number;

  @IsOptional()
  @IsNumber()
  @Min(0)
  maxFileSize?: number;

  @IsOptional()
  @IsArray()
  @IsString({ each: true })
  allowedMimeTypes?: string[];

  @IsOptional()
  @IsObject()
  retentionPolicy?: Record<string, any>;

  @IsOptional()
  @IsBoolean()
  isActive?: boolean;
}

// ============================================
// FOLDER DTOs
// ============================================

export class CreateFolderDto {
  @IsUUID()
  bucketId: string;

  @IsString()
  @MinLength(1)
  @MaxLength(200)
  name: string;

  @IsOptional()
  @IsUUID()
  parentId?: string;

  @IsOptional()
  @IsString()
  description?: string;

  @IsOptional()
  @IsString()
  @MaxLength(20)
  color?: string;

  @IsOptional()
  @IsString()
  @MaxLength(50)
  icon?: string;

  @IsOptional()
  @IsObject()
  metadata?: Record<string, any>;
}

export class UpdateFolderDto {
  @IsOptional()
  @IsString()
  @MaxLength(200)
  name?: string;

  @IsOptional()
  @IsString()
  description?: string;

  @IsOptional()
  @IsString()
  @MaxLength(20)
  color?: string;

  @IsOptional()
  @IsString()
  @MaxLength(50)
  icon?: string;

  @IsOptional()
  @IsObject()
  metadata?: Record<string, any>;
}

// ============================================
// FILE DTOs
// ============================================

export class CreateFileDto {
  @IsUUID()
  bucketId: string;

  @IsOptional()
  @IsUUID()
  folderId?: string;

  @IsString()
  @MaxLength(500)
  originalName: string;

  @IsString()
  @MaxLength(500)
  storageKey: string;

  @IsString()
  @MaxLength(100)
  mimeType: string;

  @IsNumber()
  @Min(0)
  sizeBytes: number;

  @IsOptional()
  @IsString()
  @MaxLength(64)
  checksum?: string;

  @IsOptional()
  @IsString()
  @MaxLength(30)
  category?: string;

  @IsOptional()
  @IsString()
  description?: string;

  @IsOptional()
  @IsBoolean()
  isPublic?: boolean;

  @IsOptional()
  @IsObject()
  metadata?: Record<string, any>;

  @IsOptional()
  @IsArray()
  @IsString({ each: true })
  tags?: string[];
}

export class UpdateFileDto {
  @IsOptional()
  @IsString()
  @MaxLength(500)
  originalName?: string;

  @IsOptional()
  @IsString()
  @MaxLength(30)
  category?: string;

  @IsOptional()
  @IsString()
  description?: string;

  @IsOptional()
  @IsBoolean()
  isPublic?: boolean;

  @IsOptional()
  @IsObject()
  metadata?: Record<string, any>;

  @IsOptional()
  @IsArray()
  @IsString({ each: true })
  tags?: string[];

  @IsOptional()
  @IsUUID()
  folderId?: string;
}

export class UpdateProcessingStatusDto {
  @IsString()
  @MaxLength(20)
  status: string;

  @IsOptional()
  @IsObject()
  metadata?: Record<string, any>;
}

// ============================================
// SEARCH DTOs
// ============================================

export class SearchFilesDto {
  @IsString()
  @MinLength(1)
  query: string;

  @IsOptional()
  @IsString()
  @MaxLength(30)
  category?: string;

  @IsOptional()
  @IsString()
  @MaxLength(100)
  mimeType?: string;

  @IsOptional()
  @IsBoolean()
  isPublic?: boolean;
}
