export interface KIECreateTaskRequest {
  model: 'nano-banana-2' | 'flux-2' | 'flux-2/pro-image-to-image' | 'seedream-4-5' | 'seedream5-0-lite' | 'z-image' | '4o-image' | 'flux-kontext-pro' | 'flux-kontext-max';
  prompt: string;
  negativePrompt?: string;
  referenceImages?: string[];
  aspectRatio: '1:1' | '16:9' | '9:16' | '4:3' | '3:4' | '21:9' | '3:2' | '2:3' | 'auto';
  webhookUrl?: string;
  enableTranslation?: boolean;
  seed?: number;
  outputFormat?: 'jpeg' | 'png' | 'jpg';
  safetyTolerance?: number;
  inputImage?: string;
  /** nano-banana-2: input images for transformation/reference (up to 14) */
  imageInput?: string[];
  /** flux-2/pro-image-to-image: input reference images (1-8) */
  inputUrls?: string[];
  /** nano-banana-2: resolution (1K, 2K, 4K) */
  resolution?: '1K' | '2K' | '4K';
  /** nano-banana-2: google search grounding */
  googleSearch?: boolean;
}

export interface KIETaskResponse {
  taskId: string;
  successFlag?: number; // 0=generating, 1=success, 2=create_failed, 3=generate_failed
  response?: { resultImageUrl?: string; originImageUrl?: string };
  errorMessage?: string;
  errorCode?: string;
  // Backward compat fields
  status?: 'pending' | 'processing' | 'completed' | 'failed';
  resultUrl?: string;
  error?: string;
  // Market/jobs endpoint fields (nano-banana-2, flux-2, seedream-4-5, etc.)
  state?: 'waiting' | 'processing' | 'completed' | 'failed' | 'fail' | 'queuing' | 'generating' | 'success';
  resultJson?: string;
  model?: string;
  failCode?: string | null;
  failMsg?: string | null;
}

export interface OpenRouterRequest {
  model: string;
  messages: Array<{
    role: 'system' | 'user' | 'assistant';
    content: string | Array<{ type: 'text' | 'image_url'; text?: string; image_url?: { url: string } }>;
  }>;
  temperature?: number;
  max_tokens?: number;
  top_p?: number;
}

export interface OpenRouterResponse {
  id: string;
  choices: Array<{
    message: { role: string; content: string };
    finish_reason: string;
  }>;
  usage?: { prompt_tokens: number; completion_tokens: number; total_tokens: number };
}

export interface QualityReport {
  imageId: string;
  characterId: string;
  taskId: string;
  scores: {
    characterAccuracy: number;
    bodyConsistency: number;
    environmentQuality: number;
    overallAesthetic: number;
  };
  totalScore: number;
  passed: boolean;
  feedback: string;
  createdAt: string;
}


export interface SceneTemplate {
  id: string;
  name: string;
  category: 'indoor' | 'outdoor' | 'sport' | 'social' | 'professional' | 'nightlife';
  promptTemplate: string;
  environment: { lighting: string; weather?: string; timeOfDay: string };
  defaultAspectRatio: string;
  previewImageUrl?: string;
  createdAt: string;
  updatedAt: string;
}

export interface StarsTransaction {
  id: string;
  characterId: string;
  telegramUserId: number;
  type: 'payment' | 'reaction';
  starCount: number;
  imageId?: string;
  channelId?: string;
  status: 'pending' | 'completed' | 'refunded';
  telegramPaymentId?: string;
  createdAt: string;
}

export interface CharacterAnalytics {
  characterId: string;
  period: 'daily' | 'weekly' | 'monthly';
  date: string;
  conversations: {
    totalMessages: number;
    uniqueUsers: number;
    averageConversationDuration: number;
    averageMessagesPerConversation: number;
  };
  sales: {
    totalStarsEarned: number;
    totalTransactions: number;
    conversionRate: number;
    averageStarsPerUser: number;
    topSellingHours: number[];
  };
  activity: {
    hourlyMessageCount: Record<number, number>;
    hourlyStarsCount: Record<number, number>;
    peakHour: number;
    quietHour: number;
  };
}
