export interface User {
  id: string;
  username: string;
  email: string;
  avatar?: string;
  credits: number;
  isAdmin: boolean;
  userType: string;
  allowedMenus?: string[] | null;
}

export interface CreditRecord {
  id: string;
  type: 'consume' | 'recharge' | 'refund';
  amount: number;
  description: string;
  createdAt: string;
}

export type Industry =
  | 'ecommerce'
  | 'education'
  | 'gaming'
  | 'medical'
  | 'finance'
  | 'realestate'
  | 'food'
  | 'travel'
  | 'tech'
  | 'other';

export const INDUSTRY_LABELS: Record<Industry, string> = {
  ecommerce: '电商',
  education: '教育',
  gaming: '游戏',
  medical: '医疗',
  finance: '金融',
  realestate: '房产',
  food: '餐饮',
  travel: '旅游',
  tech: '科技',
  other: '其他',
};

export interface Project {
  id: string;
  name: string;
  industry: Industry;
  createdAt: string;
  updatedAt: string;
}

export type AspectRatio = '16:9' | '9:16' | '1:1' | '4:3';
export type Resolution = '720p' | '1080p' | '4K';

export type GenerationStatus =
  | 'optimizing'
  | 'prompt_optimized'
  | 'generating'
  | 'completed'
  | 'failed';

export interface GenerationRecord {
  id: string;
  projectId: string;
  projectName: string;
  originalPrompt: string;
  optimizedPrompt: string;
  duration: number;
  aspectRatio: AspectRatio;
  resolution: Resolution;
  status: GenerationStatus;
  videoUrl?: string;
  creditsCost: number;
  createdAt: string;
  generatedAt?: string;
}

export interface GenerationParams {
  prompt: string;
  duration: number;
  aspectRatio: AspectRatio;
  resolution: Resolution;
}

export interface OptimizeResult {
  optimizedPrompt: string;
  creditsCost: number;
}

export interface LoginParams {
  username: string;
  password: string;
}

// ── Admin Types ──────────────────────────────────────

export interface AdminUser {
  id: string;
  username: string;
  email: string;
  phone?: string;
  credits: number;
  isActive: boolean;
  isAdmin: boolean;
  userType: string;
  createdAt: string;
  lastLoginAt?: string;
  allowedMenus?: string[] | null;
}

export interface AdminStats {
  totalUsers: number;
  totalProjects: number;
  totalGenerations: number;
  totalRecords: number;
  totalRevenue: number;
  creditsConsumedToday: number;
  todayAlipayRevenue: number;
  todayWechatRevenue: number;
  lastPeriodUsers: number;
  lastPeriodProjects: number;
  lastPeriodGenerations: number;
  lastPeriodRecords: number;
  lastPeriodRevenue: number;
  lastPeriodCreditsConsumed: number;
}

export interface PaymentStats {
    byStatus: Record<string, { count: number; amount: number }>;
    today: { paidCount: number; paidAmount: number };
    month: { paidCount: number; paidAmount: number };
    recent: PaymentOrder[];
}

export interface PaymentOrder {
  id: string;
  orderNo: string;
  userId: string;
  username?: string;
  amount: number;
  credits: number;
  paymentMethod: string;
  status: string;
  tradeNo?: string;
  paidAt?: string;
  createdAt: string;
  refundedAt?: string;
  refundAmount?: number;
}

export interface ModelConfig {
  id: string;
  name: string;
  provider: string;
  apiBase: string;
  apiKey: string;
  modelName: string;
  weight: number;
  maxTokens: number;
  temperature: number;
  isActive: boolean;
  priority: number;
}

export interface SystemConfig {
  id: string;
  key: string;
  value: string;
  description?: string;
}

export interface AdminNotification {
  id: string;
  title: string;
  content: string;
  type: string;
  isRead: boolean;
  createdAt: string;
}


export type GenerationAiGenType = 'image' | 'video';

export interface GenerationAiImageEngine {
  id: string;
  name: string;
  provider: string;
  modelName: string;
  supportedModels: string[];
  supportedSizes: Record<string, Record<string, string>>;
  defaultSize: string;
  priority: number;
}

export interface GenerationAiVideoEngine {
  id: string;
  name: string;
  provider: string;
  modelName: string;
  supportedModels: string[];
  supportedRatios: string[];
  supportedResolutions: string[];
  supportedDurations: number[];
  maxDuration: number;
  priority: number;
}

export interface GenerationAiEnginesResponse {
  engine: {
    image: GenerationAiImageEngine[];
    video: GenerationAiVideoEngine[];
  };
}

export interface GenerationAiEngineOption {
  id: string;
  name: string;
  provider: string;
  modelName: string;
  supportedModels?: string[];
  supportedRatios?: string[];
  supportedResolutions?: string[];
  supportedDurations?: number[];
  supportedSizes?: Record<string, Record<string, string>>;
  defaultSize?: string;
  maxDuration?: number;
  priority: number;
  genType: GenerationAiGenType;
}

export interface AdminGenerationRecord {
  id: string;
  userId: string;
  username: string;
  projectId: string;
  projectName: string;
  originalPrompt: string;
  optimizedPrompt: string;
  duration?: number;
  aspectRatio?: string;
  resolution?: string;
  status: 'optimizing' | 'prompt_optimized' | 'generating' | 'completed' | 'failed' | string;
  videoUrl?: string;
  videoCoverUrl?: string;
  references?: GenerationAIMediaReference[] | null;
  creditsCost: number;
  textCreditsCost: number;
  textTokensUsed: number;
  videoTokensUsed: number;
  errorMessage?: string;
  createdAt: string;
  generatedAt?: string;
  genType?: string;
  imageSize?: string;
  imageUrl?: string;
  imageTokensUsed?: number;
  imageProportion?: string;
  imagePx?: string;
}

export type GenerationAITaskStatus = 'pending' | 'generating' | 'completed' | 'failed' | string;

export interface GenerationAIMediaReference {
  url?: string;
  type?: string;
  name?: string;
  mediaUrl?: string;
  fileUrl?: string;
  mediaType?: string;
  mimeType?: string;
  [key: string]: unknown;
}

export interface GenerationAIEngineSnapshot {
  engineType?: string;
  id?: string;
  name?: string;
  provider?: string;
  modelName?: string;
  supportedModels?: string[];
  defaultSize?: string;
  selectedSize?: string;
  selectedProportion?: string;
  selectedPx?: string;
  selectedRatio?: string;
  selectedResolution?: string;
  selectedDuration?: number;
  [key: string]: unknown;
}

export interface GenerationAITaskOut {
  id: string;
  sourceType?: 'chat_task' | string;
  userId?: string | null;
  userName?: string | null;
  projectId?: string | null;
  genType: GenerationAiGenType | string;
  generationMode?: string | null;
  pipelineStage?: string | null;
  status: GenerationAITaskStatus;
  originalPrompt: string;
  optimizedPrompt?: string | null;
  duration?: number | null;
  aspectRatio?: string | null;
  resolution?: string | null;
  imageSize?: string | null;
  imageProportion?: string | null;
  imagePx?: string | null;
  mediaReferences?: GenerationAIMediaReference[] | null;
  providerTaskId?: string | null;
  seedanceTaskId?: string | null;
  remoteResultUrl?: string | null;
  imageUrl?: string | null;
  videoUrl?: string | null;
  videoCoverUrl?: string | null;
  engineId?: string | null;
  engineSnapshot?: GenerationAIEngineSnapshot | null;
  creditsCost: number;
  textCreditsCost: number;
  textTokensUsed: number;
  imageTokensUsed: number;
  videoTokensUsed: number;
  retryCount: number;
  pollCount: number;
  errorMessage?: string | null;
  createdAt?: string | null;
  generatedAt?: string | null;
}

export interface GenerationAITaskListOut {
  total: number;
  items: GenerationAITaskOut[];
}

export interface GenerationAITaskQueryParams {
  genType?: GenerationAiGenType | string;
  status?: GenerationAITaskStatus;
  page?: number;
  pageSize?: number;
  userId?: string;
  userName?: string;
}

