/**
 * Model Types
 * Type definitions for AI models and providers
 */

import { ComponentType } from 'react';

/**
 * Model capability type
 */
export type ModelCapabilityType = 'text-to-image' | 'image-to-image' | 'text-to-video' | 'image-to-video' | 'text-to-audio' | 'text-to-text' | 'text-to-lyrics';

/**
 * Model capabilities
 */
export interface ModelCapability {
  supportsFirstFrame?: boolean;
  supportsLastFrame?: boolean;
  supportsMultiImage?: boolean;
  supportsMultiVideo?: boolean;
  supportsRefImage?: boolean;
  supportsLora?: boolean;
}

/**
 * Model resolution configuration - Nested structure from backend
 * Example: { "1K": { "16:9": "1280*720", "9:16": "720*1280" } }
 */
export type ModelResolutions = Record<string, string | Record<string, string>>;

/**
 * Model configuration
 */
export interface ModelConfig {
  /** Unique composite ID in format 'provider/model_key' (e.g., 'dashscope/qwen-image') */
  id: string;
  /** Original model key without provider prefix (e.g., 'qwen-image') */
  model_key?: string;
  name: string;
  type: 'image' | 'video' | 'llm' | 'audio' | 'lyrics' | 'music';
  provider: string;
  /** Optional display name from backend (e.g. "阿里") */
  provider_name?: string;
  is_default: boolean;
  enabled?: boolean;
  capabilities: ModelCapability;
  /** Model resolutions - nested structure from backend config
   * Example: { "1K": { "16:9": "1280*720", "9:16": "720*1280" } }
   */
  resolutions?: ModelResolutions;
  /** 
   * Duration config - two formats:
   * - Enumerated: { values: number[] }     e.g. { values: [5, 10] }
   * - Range:      { min: number, max: number } e.g. { min: 2, max: 15 }
   */
  durations?: { values?: number[]; min?: number; max?: number };
  /**
   * Count config for generation quantity.
   * Example: { min: 1, max: 4 }.
   */
  counts?: { min?: number; max?: number; values?: number[] };
  /** Voice options for audio models (OpenAI format). id/name may be optional from some backends. */
  voices?: Array<{ id?: string; name?: string; value?: string; label?: string; gender?: string; desc?: string }>;
  icon?: ComponentType<{ size?: number }> | string;
  description?: string;
  maxTokens?: number;
  supportedFormats?: string[];
}

/**
 * Provider configuration
 */
export interface ProviderConfig {
  id: string;
  name: string;
  type: 'image' | 'video' | 'audio' | 'lyrics' | 'music' | 'llm';
  enabled: boolean;
  apiKey?: string;
  baseUrl?: string;
  models: ModelConfig[];
}

/**
 * Model defaults configuration
 */
export interface ModelDefaults {
  image: string | null;
  video: string | null;
  audio: string | null;
  lyrics: string | null;
  music: string | null;
  llm: string | null;
}

/**
 * Models API response format
 */
export interface ModelsResponse {
  data: {
    image: Record<string, ModelConfig>;
    video: Record<string, ModelConfig>;
    audio: Record<string, ModelConfig>;
    lyrics: Record<string, ModelConfig>;
    music: Record<string, ModelConfig>;
    llm: Record<string, ModelConfig>;
  };
}

/**
 * Model store state
 */
export interface ModelStoreState {
  imageModels: Record<string, ModelConfig>;
  videoModels: Record<string, ModelConfig>;
  audioModels: Record<string, ModelConfig>;
  lyricsModels: Record<string, ModelConfig>;
  musicModels: Record<string, ModelConfig>;
  llmModels: Record<string, ModelConfig>;
  defaults: ModelDefaults;
  providers: ProviderConfig[];
  isLoading: boolean;
  error: string | null;
  
  // 动作s
  setModels: (response: ModelsResponse) => void;
  fetchDefaults: () => Promise<void>;
  fetchProviders: () => Promise<void>;
}
