// Photo Storage Types — PixieSprout permanent photo management

export type PhotoType =
  | 'plant_id'
  | 'profile'
  | 'environment'
  | 'setup'
  | 'progress'
  | 'memory'
  | 'investigation'
  | 'kit'
  | 'wishlist';

export type StorageState =
  | 'full'
  | 'compressed'
  | 'thumbnail_only'
  | 'deleted'
  | 'missing';

export type PhotoRecord = {
  photoId: string;
  plantId?: string;
  relatedEntityId?: string;
  relatedEntityType?: 'plant' | 'room' | 'setup' | 'kit' | 'event' | 'scan' | 'wishlist';
  photoType: PhotoType;
  originalUri: string;
  thumbnailUri?: string;
  compressedUri?: string;
  activeUri: string;
  createdAt: string;
  fileSize?: number;
  width?: number;
  height?: number;
  storageState: StorageState;
  intelligenceStatus?: 'pending' | 'analyzing' | 'complete' | 'failed';
  description?: string;
};

export type PersistPhotoOptions = {
  plantId?: string;
  relatedEntityId?: string;
  relatedEntityType?: PhotoRecord['relatedEntityType'];
  photoType: PhotoType;
  description?: string;
  generateThumbnail?: boolean;
};

export type PhotoMetadata = {
  uri: string;
  fileSize?: number;
  width?: number;
  height?: number;
};

export type StorageUsageReport = {
  totalStorageBytes: number;
  storageByPhotoType: Record<PhotoType, number>;
  storageByPlant: Record<string, number>;
  storageByAgeBucket: {
    last30Days: number;
    last90Days: number;
    last180Days: number;
    last365Days: number;
    olderThan1Year: number;
  };
  countByPhotoType: Record<PhotoType, number>;
  largestPlantsByStorage: Array<{ plantId: string; bytes: number; count: number }>;
};

export const STORAGE_ALERT_THRESHOLDS = {
  friendly: 1_000_000_000,      // 1 GB
  stronger: 2_000_000_000,       // 2 GB
  prominent: 5_000_000_000,      // 5 GB
} as const;

export const STORAGE_ALERT_COPY = {
  friendly: "Pixie has been collecting plant memories for a while. Your plant photos are using about {size}. Would you like to review storage options?",
  stronger: "Your plant photo collection is growing! Photos are using about {size}. Consider reviewing your storage to keep things running smoothly.",
  prominent: "Pixie's photo storage is getting large at about {size}. You might want to review and manage your plant photos.",
} as const;

export const THUMBNAIL_MAX_DIMENSION = 200;
export const COMPRESSED_MAX_DIMENSION = 800;
export const COMPRESSED_JPEG_QUALITY = 0.6;

// Default recommendation for storage lifecycle
export const PHOTO_LIFECYCLE_RECOMMENDATIONS: Record<PhotoType, 'keep' | 'compress' | 'review'> = {
  plant_id: 'keep',
  profile: 'keep',
  environment: 'keep',
  setup: 'keep',
  progress: 'compress',
  memory: 'review',
  investigation: 'compress',
  kit: 'keep',
  wishlist: 'keep',
};
