import { Argument , Attribute } from '../arguments' ; import { Util } from '../Util' ; category export abstract class Block { readonly blockType : string ; readonly blockNames : string [ ] ; readonly #arguments : Record < string , any > ; #innerBlocks : Block [ ] ; param type param names param args constructor ( type , names , args ? , innerBlocks ? ) { this . #validateIdentifier ( type ) ; names . forEach ( name => { this . #validateIdentifier ( name ) ; } ) ; this . blockType = type ; this . blockNames = names ; this . #arguments = args ? args : { } ; this . #innerBlocks = innerBlocks ? innerBlocks : [ ] ; } /**
     * Get arguments.
     */ getArguments ( ) { return this . #arguments ; } param key getArgument ( key ) { return this . #arguments [ key ] ; } param key param value setArgument ( key , value ) { this . #arguments [ key ] = value ; return this ; } param args setArguments ( args ) { for ( const key in args ) { this . #arguments [ key ] = args [ key ] ; } return this ; } param key deleteArgument ( key ) { delete this . #arguments [ key ] ; return this ; } /**
     * Get inner blocks.
     */ protected getInnerBlocks ( ) { return this . #innerBlocks ; } /**
     * Set inner blocks.
     */ protected setInnerBlocks ( innerBlocks ) { this . #innerBlocks = innerBlocks ? innerBlocks : [ ] ; return this ; } /**
     * To Terraform representation.
     */ toTerraform ( ) { let str = this . blockType ; this . blockNames . forEach ( name => { str += ` "${ name }"` ; } ) ; str += '{\n' ; str += Util . argumentsToString ( this . #arguments ) ; this . #innerBlocks . forEach ( block => { str += `${ block . toTerraform ( ) . trim ( ) }\n` ; } ) ; str += '}\n\n' ; return Util . escape ( str ) ; } /**
     * Represent block as argument.
     */ abstract asArgument ( ) ; param name abstract attr ( name ) ; /**
     * Block's id attribute.
     */ get id ( ) : Attribute { return this . attr ( 'id' ) ; } #validateIdentifier ( identifier ) { if ( ! identifier . match ( /^[a-zA-Z_\-]{1}[0-9a-zA-Z_\-]*$/ ) ) { throw new Error ( `Invalid identifier: ${ identifier }` ) ; } } }