import type { PlantType } from '../../types/plantScan';

export type PlantArtworkProviderName = 'mock-dev' | 'openai' | 'claude' | 'unknown';

export type PlantArtworkStylePreset = 'pixiesprout_watercolor_icon';

export type PlantArtworkInput = {
  plantId: string;
  commonName: string;
  scientificName?: string;
  plantType: PlantType;
  imageReferenceUri?: string;
  stylePreset: PlantArtworkStylePreset;
};

export type PlantArtworkResult = {
  id: string;
  imageUri?: string;
  imageBase64?: string;
  mimeType?: 'image/png' | 'image/jpeg';
  promptUsed: string;
  provider: PlantArtworkProviderName;
  stylePreset: PlantArtworkStylePreset;
  createdAt: string;
  rawResponse?: unknown;
};

export type PlantArtworkProvider = {
  name: PlantArtworkResult['provider'];
  generatePlantArtwork(input: PlantArtworkInput): Promise<PlantArtworkResult>;
};

export type PlantArtworkErrorCode =
  | 'MISSING_PROVIDER'
  | 'MISSING_API_KEY'
  | 'PROVIDER_UNAVAILABLE'
  | 'GENERATION_FAILED';

export class PlantArtworkError extends Error {
  code: PlantArtworkErrorCode;
  devMessage?: string;

  constructor(code: PlantArtworkErrorCode, message: string, devMessage?: string) {
    super(message);
    Object.setPrototypeOf(this, PlantArtworkError.prototype);
    this.name = 'PlantArtworkError';
    this.code = code;
    if (devMessage !== undefined) this.devMessage = devMessage;
  }
}
