import * as ssm from "aws-cdk-lib/aws-ssm";
import { Construct } from "constructs";
import { FunctionConfig } from "@serverless-stack/core";
import { assertNameNotInUse } from "./Config.js";
/**
 * The `Parameter` construct is a higher level CDK construct that makes it easy to manage app environment variables.
 *
 * @example
 * ### Using the minimal config
 *
 * ```js
 * import { Config } from "@serverless-stack/resources";
 *
 * new Config.Parameter(stack, "TABLE_NAME", table.tableName);
 * ```
 */
export class Parameter extends Construct {
    constructor(scope, id, props) {
        super(scope, id);
        const { value } = props;
        const app = scope.node.root;
        this.name = id;
        this.value = value;
        assertNameNotInUse(id);
        Parameter.all.add(id);
        // Create SSM parameter
        new ssm.StringParameter(this, "Parameter", {
            parameterName: FunctionConfig.buildSsmNameForParameter(app.name, app.stage, id),
            stringValue: value
        });
    }
    /** @internal */
    static getAllNames() {
        return Array.from(Parameter.all);
    }
    /** @internal */
    static hasName(name) {
        return Parameter.all.has(name);
    }
    /** @internal */
    static clear() {
        Parameter.all.clear();
    }
    /** @internal */
    getConstructMetadata() {
        return {
            type: "Parameter",
            data: {
                name: this.name
            }
        };
    }
}
Parameter.all = new Set();
