import type { ImageSource } from './models';

// ========================================
// GENERATION ENDPOINTS
// ========================================

export interface CreateGenerationRequest {
  prompt: string;
  referenceImages?: string[]; // Array of aliases to resolve
  aspectRatio?: string; // e.g., "1:1", "16:9", "3:2", "9:16"
  flowId?: string;
  alias?: string; // Alias to assign to generated image
  flowAlias?: string; // Flow-scoped alias to assign
  autoEnhance?: boolean;
  enhancementOptions?: {
    template?: 'photorealistic' | 'illustration' | 'minimalist' | 'sticker' | 'product' | 'comic' | 'general';
  };
  meta?: Record<string, unknown>;
}

export interface ListGenerationsQuery {
  flowId?: string;
  status?: string;
  limit?: number;
  offset?: number;
  includeDeleted?: boolean;
}

export interface RetryGenerationRequest {
  prompt?: string; // Optional: override original prompt
  aspectRatio?: string; // Optional: override original aspect ratio
}

export interface UpdateGenerationRequest {
  prompt?: string; // Change prompt (triggers regeneration)
  aspectRatio?: string; // Change aspect ratio (triggers regeneration)
  flowId?: string | null; // Change/remove/add flow association (null to detach)
  meta?: Record<string, unknown>; // Update metadata
}

// ========================================
// IMAGE ENDPOINTS
// ========================================

export interface UploadImageRequest {
  alias?: string; // Project-scoped alias
  flowId?: string;
  flowAlias?: string; // Flow-scoped alias
  meta?: Record<string, unknown>;
}

export interface ListImagesQuery {
  flowId?: string;
  source?: ImageSource;
  alias?: string;
  limit?: number;
  offset?: number;
  includeDeleted?: boolean;
}

export interface UpdateImageRequest {
  // Removed alias (Section 6.1) - use PUT /images/:id/alias instead
  focalPoint?: {
    x: number; // 0.0 to 1.0
    y: number; // 0.0 to 1.0
  };
  meta?: Record<string, unknown>;
}

export interface DeleteImageQuery {
  hard?: boolean; // If true, perform hard delete; otherwise soft delete
}

// ========================================
// FLOW ENDPOINTS
// ========================================

export interface CreateFlowRequest {
  meta?: Record<string, unknown>;
}

export interface ListFlowsQuery {
  limit?: number;
  offset?: number;
}

export interface UpdateFlowAliasesRequest {
  aliases: Record<string, string>; // { alias: imageId }
  merge?: boolean; // If true, merge with existing; otherwise replace
}

// ========================================
// LIVE GENERATION ENDPOINT
// ========================================

export interface LiveGenerationQuery {
  prompt: string;
  aspectRatio?: string;
  autoEnhance?: boolean;
  template?: 'photorealistic' | 'illustration' | 'minimalist' | 'sticker' | 'product' | 'comic' | 'general';
}

// ========================================
// LIVE SCOPE ENDPOINTS
// ========================================

export interface CreateLiveScopeRequest {
  slug: string;
  allowNewGenerations?: boolean;
  newGenerationsLimit?: number;
  meta?: Record<string, unknown>;
}

export interface ListLiveScopesQuery {
  slug?: string;
  limit?: number;
  offset?: number;
}

export interface UpdateLiveScopeRequest {
  allowNewGenerations?: boolean;
  newGenerationsLimit?: number;
  meta?: Record<string, unknown>;
}

export interface RegenerateScopeRequest {
  imageId?: string; // Optional: regenerate specific image
}

// ========================================
// ANALYTICS ENDPOINTS
// ========================================

export interface AnalyticsSummaryQuery {
  flowId?: string;
  startDate?: string; // ISO date string
  endDate?: string; // ISO date string
}

export interface AnalyticsTimelineQuery {
  flowId?: string;
  startDate?: string; // ISO date string
  endDate?: string; // ISO date string
  granularity?: 'hour' | 'day' | 'week';
}

// ========================================
// COMMON TYPES
// ========================================

export interface PaginationQuery {
  limit?: number;
  offset?: number;
}
