#!/usr/bin/env node
import * as cdk from 'aws-cdk-lib';
import { getConfig, BuildConfig } from '../utils/build-config';
import { MccAPIInfraStack } from './apiStack';
import { MccDBInfraStack } from './rdsStack';

const app = new cdk.App();
const buildConfig: BuildConfig = getConfig(app);

const qualifier = process.env.CDK_QUALIFIER;

const stackName = `${buildConfig.Environment}${buildConfig.ApplicationShortName}`;

cdk.Tags.of(app).add('App', buildConfig.ApplicationName);
cdk.Tags.of(app).add('Environment', buildConfig.Environment);
cdk.Tags.of(app).add('AppManagerCFNStackKey', stackName);
cdk.Tags.of(app).add('purpose', `${buildConfig.Environment}-${buildConfig.ApplicationShortName}`);

const env: cdk.Environment = {
  account: buildConfig.Account ?? process.env.CDK_DEPLOY_ACCOUNT ?? process.env.CDK_DEFAULT_ACCOUNT,
  region: buildConfig.Region ?? process.env.CDK_DEPLOY_REGION ?? process.env.CDK_DEFAULT_REGION,
};

const apiStack = new MccAPIInfraStack(app, `${stackName}MCCAPI`, buildConfig, {
  env,
  description: `API stack for ${buildConfig.ApplicationName} in ${buildConfig.Environment}`,
  synthesizer: new cdk.DefaultStackSynthesizer({
    qualifier,
  }),
});

const dbStack = new MccDBInfraStack(app, `${stackName}MCCDB`, buildConfig, {
  env,
  description: `Database stack for ${buildConfig.ApplicationName} in ${buildConfig.Environment}`,
  synthesizer: new cdk.DefaultStackSynthesizer({
    qualifier,
  }),
});

