import * as cdk from "aws-cdk-lib";
import * as apigateway from "aws-cdk-lib/aws-apigateway";
import { RetentionDays } from "aws-cdk-lib/aws-logs";

export interface Context {
  domainProps: {
    enableSubDomain: boolean;
  };
  networkProps: {
    natGatewayNum: number;
    maxAzs: number;
  };
  authProps: {
    enableUserPoolCustomDomain: boolean;
    applicationLogLevel: string;
    sesFromEmail: string;
  };
  dbProps: {
    minAcuCapacity: number;
    maxAcuCapacity: number;
    enableRdsProxy: boolean;
    enableInsights: boolean;
  };
  apiProps: {
    allowedApiCallOriginList: string[];
    lambdaIntegrationTimeout: number;
    enableSnapStart: boolean;
    enableMonitoring: boolean;
    enableXray: boolean;
    enableDlqAlarm: boolean;
    enableContractEventAlert: boolean;
    consumerConcurrencyLimit: number;
    applicationLogLevel: string;
  };
  backupProps: {
    backupRetentionDays: cdk.Duration;
  };
  frontendProps: {
    enableAccessLog: boolean;
    logRetentionDays: RetentionDays;
  };
}

export const context: Record<string, Context> = {
  dev: {
    domainProps: {
      enableSubDomain: true,
    },
    networkProps: {
      natGatewayNum: 1,
      maxAzs: 2,
    },
    authProps: {
      enableUserPoolCustomDomain: false,
      applicationLogLevel: "info",
      sesFromEmail: "ai-unit-dev@ml.works-hi.com",
    },
    dbProps: {
      minAcuCapacity: 0,
      maxAcuCapacity: 1,
      enableRdsProxy: false,
      enableInsights: false,
    },
    apiProps: {
      allowedApiCallOriginList: apigateway.Cors.ALL_ORIGINS,
      lambdaIntegrationTimeout: 120,
      enableSnapStart: false,
      enableMonitoring: false,
      enableXray: false,
      enableDlqAlarm: false,
      enableContractEventAlert: false,
      consumerConcurrencyLimit: 10,
      applicationLogLevel: "info",
    },
    backupProps: {
      backupRetentionDays: cdk.Duration.days(1),
    },
    frontendProps: {
      enableAccessLog: false,
      logRetentionDays: RetentionDays.ONE_WEEK,
    },
  },
  stg: {
    domainProps: {
      enableSubDomain: false,
    },
    networkProps: {
      natGatewayNum: 2,
      maxAzs: 2,
    },
    authProps: {
      enableUserPoolCustomDomain: true,
      applicationLogLevel: "info",
      sesFromEmail: "ai-unit-dev@ml.works-hi.com",
    },
    dbProps: {
      minAcuCapacity: 5,
      maxAcuCapacity: 20,
      enableRdsProxy: true,
      enableInsights: true,
    },
    apiProps: {
      allowedApiCallOriginList: apigateway.Cors.ALL_ORIGINS,
      lambdaIntegrationTimeout: 120,
      enableSnapStart: true,
      enableMonitoring: true,
      enableXray: true,
      enableDlqAlarm: true,
      enableContractEventAlert: true,
      consumerConcurrencyLimit: 300,
      applicationLogLevel: "info",
    },
    backupProps: {
      backupRetentionDays: cdk.Duration.days(7),
    },
    frontendProps: {
      enableAccessLog: true,
      logRetentionDays: RetentionDays.THREE_MONTHS,
    },
  },
  prod: {
    domainProps: {
      enableSubDomain: false,
    },
    networkProps: {
      natGatewayNum: 3,
      maxAzs: 3,
    },
    authProps: {
      enableUserPoolCustomDomain: true,
      applicationLogLevel: "info",
      sesFromEmail: "ai-unit-noreply@works-hi.co.jp",
    },
    dbProps: {
      minAcuCapacity: 10,
      maxAcuCapacity: 30,
      enableRdsProxy: true,
      enableInsights: true,
    },
    apiProps: {
      allowedApiCallOriginList: apigateway.Cors.ALL_ORIGINS,
      lambdaIntegrationTimeout: 120,
      enableSnapStart: true,
      enableMonitoring: true,
      enableXray: true,
      enableDlqAlarm: true,
      enableContractEventAlert: true,
      consumerConcurrencyLimit: 1000,
      applicationLogLevel: "info",
    },
    backupProps: {
      backupRetentionDays: cdk.Duration.days(35),
    },
    frontendProps: {
      enableAccessLog: true,
      logRetentionDays: RetentionDays.EIGHTEEN_MONTHS,
    },
  },
};
