import {
  PlatformConfig,
  PlatformTemplate,
  SupportedEnvironments,
  SupportedRegions
} from 'types'

export class PlatformConfigService {

  static from(template: PlatformTemplate): PlatformConfig {

    const withDefaults = {
      platformName: SupportedEnvironments.LOCAL,
      domain: 'localhost',
      activeEnvironment: SupportedEnvironments.LOCAL,
      supportedDeploymentTypes: ['CONTAINER'],
      ciSubDomain: 'ci',
      ciInternalServerPort: 3000,
      ciServerName: 'ci-client',
      ciDockerNetworkName: 'deployment-tools',
      awsRegion: SupportedRegions.North,
      ...template
    }

    const awsDeploymentSqsArn = `https://sqs.${withDefaults.awsRegion}.amazonaws.com/${withDefaults.awsAccountId}/${withDefaults.platformName}-${withDefaults.activeEnvironment}`
    const awsRoleToAssume = process.env.CI ? 'github-ci-role' : undefined

    return {
      ...withDefaults,
      awsDeploymentSqsArn,
      awsRoleToAssume
    }

  }

}
