import { resources } from './aws-resources';
import { customResource } from './cloudformation';
import { TemplateBuilder } from './template/template-builder';
class Builder {
    aws;
    constructor(aws) {
        this.aws = aws;
    }
    create(outputFileName = 'template.json', parametersFileName = 'parameters.json') {
        return TemplateBuilder.create(this.aws, outputFileName, parametersFileName);
    }
}
export class AwsLoader {
    aws = {};
    promises = [];
    constructor() {
        this.aws = {
            customResource
        };
    }
    async add(service) {
        const parts = await Promise.all(Object.keys(resources.aws[service]).map(async (resource) => ({ [resource]: await resources.aws[service][resource].load() })));
        this.aws = { ...this.aws, [service]: parts.reduce((prev, next) => ({ ...prev, ...next }), {}) };
    }
    register(...service) {
        this.promises.push(...service.map(it => this.add(it)));
        return this;
    }
    static register(...resource) {
        return new AwsLoader().register(...resource);
    }
    async load() {
        await Promise.all(this.promises);
        return new Builder(this.aws);
    }
}
