"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const cdk = require("@aws-cdk/cdk");
const log_stream_1 = require("./log-stream");
const logs_generated_1 = require("./logs.generated");
const metric_filter_1 = require("./metric-filter");
const subscription_filter_1 = require("./subscription-filter");
/**
 * A new CloudWatch Log Group
 */
class LogGroup extends cdk.Construct {
    constructor(parent, id, props = {}) {
        super(parent, id);
        let retentionInDays = props.retentionDays;
        if (retentionInDays === undefined) {
            retentionInDays = 730;
        }
        if (retentionInDays === Infinity) {
            retentionInDays = undefined;
        }
        if (retentionInDays !== undefined && retentionInDays <= 0) {
            throw new Error(`retentionInDays must be positive, got ${retentionInDays}`);
        }
        const resource = new logs_generated_1.cloudformation.LogGroupResource(this, 'Resource', {
            logGroupName: props.logGroupName,
            retentionInDays,
        });
        if (props.retainLogGroup !== false) {
            cdk.applyRemovalPolicy(resource, cdk.RemovalPolicy.Orphan);
        }
        this.logGroupArn = resource.logGroupArn;
        this.logGroupName = resource.ref;
    }
    /**
     * Create a new Log Stream for this Log Group
     *
     * @param parent Parent construct
     * @param id Unique identifier for the construct in its parent
     * @param props Properties for creating the LogStream
     */
    newStream(parent, id, props = {}) {
        return new log_stream_1.LogStream(parent, id, Object.assign({ logGroup: this }, props));
    }
    /**
     * Create a new Subscription Filter on this Log Group
     *
     * @param parent Parent construct
     * @param id Unique identifier for the construct in its parent
     * @param props Properties for creating the SubscriptionFilter
     */
    newSubscriptionFilter(parent, id, props) {
        return new subscription_filter_1.SubscriptionFilter(parent, id, Object.assign({ logGroup: this }, props));
    }
    /**
     * Create a new Metric Filter on this Log Group
     *
     * @param parent Parent construct
     * @param id Unique identifier for the construct in its parent
     * @param props Properties for creating the MetricFilter
     */
    newMetricFilter(parent, id, props) {
        return new metric_filter_1.MetricFilter(parent, id, Object.assign({ logGroup: this }, props));
    }
}
exports.LogGroup = LogGroup;
/**
 * Name of a log group
 */
class LogGroupName extends cdk.Token {
}
exports.LogGroupName = LogGroupName;
//# sourceMappingURL=data:application/json;base64,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