/*
 * Elastic License 2.0
 * Copyright (C) 2025–present Raman Marozau, Work Target Insight Function. All rights reserved.
 * Contact: raman@worktif.com
 *
 * This file is part of the Licensed Work: worktif.runtime.cdk <worktif_runtime_cdk>.
 * Use of this software is governed by the Elastic License 2.0; see the LICENSE file
 * or https://www.elastic.co/licensing/elastic-license for details.
 *
 * Re-licensing notice:
 *   This file was previously distributed under the Business Source License 1.1 (BUSL-1.1).
 *   As of 2025-09-22, it is re-licensed under Elastic License 2.0.
 *
 * SPDX-License-Identifier: Elastic-2.0
 */

import { RuntimeConfig } from '@worktif/runtime';

/**
 * Runtime CLI Configuration
 *
 * This file defines the configuration for your Runtime application,
 * including deployment stages, paths, and feature flags.
 */
const config: RuntimeConfig = {
  /**
   * Project name used for AWS resource naming
   */
  projectName: '{{PROJECT_NAME}}',

  /**
   * Deployment stages configuration
   * Each stage can have its own AWS region, profile, and domain settings
   * Note: Region is resolved from AWS SDK default provider chain (env vars, ~/.aws/config)
   * The awsRegion value here is used as a fallback if no region is configured
   */
  stages: [
    {
      name: 'dev',
      awsRegion: '{{REGION}}', // Fallback region if not configured in AWS
      awsProfile: 'default', // Optional: AWS CLI profile name
      // domain: 'example.com', // Optional: Custom domain
      // subdomain: 'dev', // Optional: Subdomain prefix
    },
    {
      name: 'staging',
      awsRegion: 'us-east-1', // Fallback region if not configured in AWS
      awsProfile: 'default',
      // domain: 'example.com',
      // subdomain: 'staging',
    },
    {
      name: 'prod',
      awsRegion: 'us-east-2', // Fallback region if not configured in AWS
      awsProfile: 'default',
      // domain: 'example.com',
      // subdomain: 'www',
    },
  ],

  /**
   * Project paths configuration
   */
  paths: {
    srcDir: 'src',
    reactEntry: 'src/index.tsx',
    outDir: 'out/dist',
    cdkDir: 'cdk', // Optional: CDK infrastructure directory
  },

  /**
   * Infrastructure mode
   * - 'cdk': Use AWS CDK for infrastructure (recommended)
   * - 'auto': Automatic infrastructure management
   */
  infraMode: 'cdk',

  /**
   * Optional feature flags
   */
  features: {
    /**
     * Enable SEO metadata storage in DynamoDB
     */
    enableSeo: false,

    /**
     * Enable web app manifest generation
     */
    enableManifest: true,

    /**
     * Enable Lambda warmup to reduce cold starts
     */
    enableWarmup: false,

    /**
     * A configuration setting that determines whether the cache should be cleared on deployment.
     * When set to true, the cache will be cleared every time a deployment occurs.
     */
    clearCacheOnDeploy: true,
  },

  /**
   * Awake Lambda Development configuration (optional)
   *
   * Enables debugging real AWS Lambda invocations on your local machine.
   * All values can be overridden via CLI options (CLI takes priority).
   *
   * To use Live Dev:
   * 1. Deploy the Live Dev stack: npx cdk deploy {projectName}-RuntimeAwake-{stage}
   * 2. Start Live Dev: npx runtime dev --live
   *
   * Run diagnostics: npx runtime dev doctor
   */
  // awake: {
  //   /**
  //    * Enable Awake Lambda Development
  //    */
  //   enabled: true,
  //
  //   /**
  //    * Developer ID for session isolation (optional)
  //    * If not set, derived from system username + project name
  //    * CLI override: --dev-id
  //    */
  //   // devId: 'john.doe',
  //
  //   /**
  //    * Fallback behavior when local CLI is offline
  //    * - 'execute': Execute the original handler in the cloud (default)
  //    * - 'error': Return 503 "Live dev session not connected"
  //    * CLI override: --fallback
  //    */
  //   // fallbackMode: 'execute',
  //
  //   /**
  //    * Custom Live Dev stack name (optional)
  //    * Default: {projectName}-RuntimeAwake-{stage}
  //    * CLI override: --stack-name
  //    */
  //   // runtimeAwakeStackName: 'custom-stack-name',
  //
  //   /**
  //    * List of developer IAM user ARNs for IoT policies (CDK only)
  //    */
  //   // allowedDevelopers: [
  //   //   'arn:aws:iam::123456789012:user/developer1',
  //   // ],
  //
  //   /**
  //    * Session TTL in seconds for DynamoDB auto-expiry (CDK only)
  //    * @default 120
  //    */
  //   // sessionTtlSeconds: 120,
  //
  //   /**
  //    * Payload TTL in days for S3 lifecycle rules (CDK only)
  //    * @default 1
  //    */
  //   // payloadTtlDays: 1,
  //
  //   /**
  //    * Session configuration for heartbeats and timeouts
  //    */
  //   // session: {
  //   //   heartbeatIntervalMs: 30000,  // CLI sends heartbeats to keep session alive
  //   //   timeoutMs: 60000,            // Session expires if no heartbeat
  //   // },
  //
  //   /**
  //    * File watching configuration for hot reload
  //    * CLI override: --no-watch disables watching
  //    */
  //   // watch: {
  //   //   enabled: true,
  //   //   paths: ['./src'],
  //   //   ignore: ['node_modules', '*.test.ts', '*.spec.ts', '__tests__'],
  //   //   debounceMs: 100,
  //   // },
  //
  //   /**
  //    * Debug configuration for logging and inspector
  //    * CLI overrides: --verbose, --inspector-port, --debug-full-payload
  //    */
  //   // debug: {
  //   //   inspectorPort: 9229,         // Node.js inspector port
  //   //   logLevel: 'info',            // 'debug' | 'info' | 'warn' | 'error'
  //   //   maskSecrets: true,           // Mask sensitive data in logs
  //   //   fullPayloadLogging: false,   // Log full request/response payloads
  //   // },
  //
  //   /**
  //    * VPC Agent configuration for accessing private resources (RDS, Redis, etc.)
  //    */
  //   // vpcAgent: {
  //   //   enabled: false,
  //   //   url: 'https://your-vpc-agent.lambda-url.us-east-1.on.aws',
  //   //   proxyHosts: ['your-rds.cluster.us-east-1.rds.amazonaws.com'],
  //   //   allowedPorts: [5432, 6379, 3306],
  //   // },
  // },
};

export default config;
