"use strict";var _a,_b;Object.defineProperty(exports,"__esModule",{value:!0}),exports.FunctionEventType=exports.Function=exports.FunctionCode=void 0;const jsiiDeprecationWarnings=require("../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),fs=require("fs"),cloudfront_generated_1=require("./cloudfront.generated"),core_1=require("../../core");class FunctionCode{static fromInline(code){return new InlineCode(code)}static fromFile(options){try{jsiiDeprecationWarnings.aws_cdk_lib_aws_cloudfront_FileCodeOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.fromFile),error}return new FileCode(options)}}exports.FunctionCode=FunctionCode,_a=JSII_RTTI_SYMBOL_1,FunctionCode[_a]={fqn:"aws-cdk-lib.aws_cloudfront.FunctionCode",version:"2.96.1"};class InlineCode extends FunctionCode{constructor(code){super(),this.code=code}render(){return this.code}}class FileCode extends FunctionCode{constructor(options){super(),this.options=options}render(){return fs.readFileSync(this.options.filePath,{encoding:"utf-8"})}}class Function extends core_1.Resource{static fromFunctionAttributes(scope,id,attrs){try{jsiiDeprecationWarnings.aws_cdk_lib_aws_cloudfront_FunctionAttributes(attrs)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.fromFunctionAttributes),error}return new class extends core_1.Resource{constructor(){super(...arguments),this.functionName=attrs.functionName,this.functionArn=attrs.functionArn}}(scope,id)}constructor(scope,id,props){super(scope,id);try{jsiiDeprecationWarnings.aws_cdk_lib_aws_cloudfront_FunctionProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,Function),error}this.functionName=props.functionName??this.generateName();const resource=new cloudfront_generated_1.CfnFunction(this,"Resource",{autoPublish:!0,functionCode:props.code.render(),functionConfig:{comment:props.comment??this.functionName,runtime:"cloudfront-js-1.0"},name:this.functionName});this.functionArn=resource.attrFunctionArn,this.functionStage=resource.attrStage}generateName(){const name=core_1.Stack.of(this).region+core_1.Names.uniqueId(this);return name.length>64?name.substring(0,32)+name.substring(name.length-32):name}}exports.Function=Function,_b=JSII_RTTI_SYMBOL_1,Function[_b]={fqn:"aws-cdk-lib.aws_cloudfront.Function",version:"2.96.1"};var FunctionEventType;(function(FunctionEventType2){FunctionEventType2.VIEWER_REQUEST="viewer-request",FunctionEventType2.VIEWER_RESPONSE="viewer-response"})(FunctionEventType||(exports.FunctionEventType=FunctionEventType={}));
