import * as cdk from "aws-cdk-lib";
import { PublicHostedZone } from "aws-cdk-lib/aws-route53";
import * as ssm from "aws-cdk-lib/aws-ssm";
import { Construct } from "constructs";

export type DomainProps = {
  readonly zoneName: string;
};

interface StackProps extends cdk.StackProps {
  readonly domainProps: DomainProps;
}

export class DomainStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props: StackProps) {
    super(scope, id, props);

    const { zoneName } = props.domainProps;

    const zone = new PublicHostedZone(this, "Zone", {
      zoneName,
    });

    new ssm.StringParameter(this, "ParamHostedZoneId", {
      parameterName: `/account/hosted-zone-id`,
      stringValue: zone.hostedZoneId,
    });

    new ssm.StringParameter(this, "ParamHostedZoneName", {
      parameterName: `/account/hosted-zone-name`,
      stringValue: zone.zoneName,
    });
  }
}
