/**
 * @fileoverview OrdoJS CLI - Deployment adapter interface
 * Defines the interface for deployment adapters
 */

import { OptimizationResults } from '../asset-optimizer.js';

/**
 * Deployment target configuration
 */
export interface DeploymentConfig {
  /**
   * Output directory for the build
   */
  outputDir: string;

  /**
   * Environment variables for the deployment
   */
  env?: Record<string, string>;

  /**
   * Deployment-specific settings
   */
  settings?: Record<string, any>;

  /**
   * Path to routes directory
   */
  routesDir?: string;

  /**
   * Whether the deployment is for a static site
   */
  isStatic?: boolean;

  /**
   * Whether to include server functions
   */
  includeServerFunctions?: boolean;

  /**
   * Custom domain configuration
   */
  domain?: {
    name: string;
    useHttps: boolean;
    aliases?: string[];
  };

  /**
   * Headers to add to the deployment
   */
  headers?: Array<{
    source: string;
    headers: Array<{
      key: string;
      value: string;
    }>;
  }>;

  /**
   * Redirects to add to the deployment
   */
  redirects?: Array<{
    source: string;
    destination: string;
    permanent: boolean;
  }>;
}

/**
 * Deployment result
 */
export interface DeploymentResult {
  /**
   * Whether the deployment preparation was successful
   */
  success: boolean;

  /**
   * Error message if the deployment failed
   */
  error?: string;

  /**
   * Generated configuration files
   */
  generatedFiles: Array<{
    path: string;
    content: string;
  }>;

  /**
   * Deployment instructions
   */
  instructions: string;

  /**
   * Deployment URL (if available)
   */
  deploymentUrl?: string;

  /**
   * Optimization results
   */
  optimizationResults?: OptimizationResults;
}

/**
 * Deployment adapter interface
 */
export interface DeploymentAdapter {
  /**
   * Name of the deployment adapter
   */
  name: string;

  /**
   * Description of the deployment adapter
   */
  description: string;

  /**
   * Validate the deployment configuration
   * @param config Deployment configuration
   * @returns Validation result
   */
  validateConfig(config: DeploymentConfig): {
    valid: boolean;
    errors?: string[];
  };

  /**
   * Prepare the deployment
   * @param config Deployment configuration
   * @returns Deployment result
   */
  prepareDeployment(config: DeploymentConfig): Promise<DeploymentResult>;

  /**
   * Generate deployment-specific optimizations
   * @param config Deployment configuration
   * @param outputDir Output directory
   * @returns Optimization results
   */
  optimizeForDeployment(config: DeploymentConfig, outputDir: string): Promise<OptimizationResults>;

  /**
   * Get deployment-specific environment variables
   * @param config Deployment configuration
   * @returns Environment variables
   */
  getEnvironmentVariables(config: DeploymentConfig): Record<string, string>;

  /**
   * Get deployment command
   * @param config Deployment configuration
   * @returns Deployment command
   */
  getDeployCommand(config: DeploymentConfig): string;
}
