"use strict";var _a,_b;Object.defineProperty(exports,"__esModule",{value:!0}),exports.MultiNodeJobDefinition=exports.OptimalInstanceType=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var batch_generated_1=()=>{var tmp=require("./batch.generated");return batch_generated_1=()=>tmp,tmp},ecs_job_definition_1=()=>{var tmp=require("./ecs-job-definition");return ecs_job_definition_1=()=>tmp,tmp},job_definition_base_1=()=>{var tmp=require("./job-definition-base");return job_definition_base_1=()=>tmp,tmp},ec2=()=>{var tmp=require("../../aws-ec2");return ec2=()=>tmp,tmp},core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp};class OptimalInstanceType extends ec2().InstanceType{constructor(){super("optimal")}}exports.OptimalInstanceType=OptimalInstanceType,_a=JSII_RTTI_SYMBOL_1,OptimalInstanceType[_a]={fqn:"aws-cdk-lib.aws_batch.OptimalInstanceType",version:"2.148.1"};class MultiNodeJobDefinition extends job_definition_base_1().JobDefinitionBase{static fromJobDefinitionArn(scope,id,jobDefinitionArn){const jobDefinitionName=core_1().Stack.of(scope).splitArn(jobDefinitionArn,core_1().ArnFormat.SLASH_RESOURCE_NAME).resourceName;class Import extends job_definition_base_1().JobDefinitionBase{constructor(){super(...arguments),this.jobDefinitionArn=jobDefinitionArn,this.jobDefinitionName=jobDefinitionName,this.enabled=!0}}return new Import(scope,id)}constructor(scope,id,props){super(scope,id,props);try{jsiiDeprecationWarnings().aws_cdk_lib_aws_batch_MultiNodeJobDefinitionProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,MultiNodeJobDefinition),error}this.containers=props?.containers??[],this.mainNode=props?.mainNode,this._instanceType=props?.instanceType,this.propagateTags=props?.propagateTags;const resource=new(batch_generated_1()).CfnJobDefinition(this,"Resource",{...(0,job_definition_base_1().baseJobDefinitionProperties)(this),type:"multinode",jobDefinitionName:props?.jobDefinitionName,propagateTags:this.propagateTags,nodeProperties:{mainNode:this.mainNode??0,nodeRangeProperties:core_1().Lazy.any({produce:()=>this.containers.map(container=>({targetNodes:container.startNode+":"+container.endNode,container:{...container.container._renderContainerDefinition(),instanceType:this._instanceType?.toString()}}))}),numNodes:core_1().Lazy.number({produce:()=>computeNumNodes(this.containers)})},platformCapabilities:[ecs_job_definition_1().Compatibility.EC2]});this.jobDefinitionArn=this.getResourceArnAttribute(resource.ref,{service:"batch",resource:"job-definition",resourceName:this.physicalName}),this.jobDefinitionName=this.getResourceNameAttribute(resource.ref),this.node.addValidation({validate:()=>validateContainers(this.containers)})}get instanceType(){return this._instanceType?this._instanceType:new OptimalInstanceType}addContainer(container){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_batch_MultiNodeContainer(container)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.addContainer),error}this.containers.push(container)}}exports.MultiNodeJobDefinition=MultiNodeJobDefinition,_b=JSII_RTTI_SYMBOL_1,MultiNodeJobDefinition[_b]={fqn:"aws-cdk-lib.aws_batch.MultiNodeJobDefinition",version:"2.148.1"};function computeNumNodes(containers){let result=0;for(const container of containers)result+=container.endNode-container.startNode+1;return result}function validateContainers(containers){return containers.length===0?["multinode job has no containers!"]:[]}
