import { codeBlock , documentationBlock } from '@sap-cloud-sdk/util' ; import { linkClass } from '../../generator-utils' ; import { getStaticNavPropertyDescription } from '../../typedoc' ; import { VdmEntity , VdmServiceMetadata , VdmNavigationProperty } from '../../vdm-types' ; import { matchEntity } from './match-entity' ; export function navigationPropertyFieldsVariable ( entity , service ) { return codeBlock `private navigationPropertyFields!: {
    ${ navigationPropertyTypes ( entity , service ) . join ( ',\n' ) }
  };` ; } export function addNavigationPropertyFieldsFunction ( entity , service ) { return codeBlock `_addNavigationProperties(
    linkedApis: [
      ${ navigationPropertyApiTypes ( entity , service ) . join ( ',' ) }
    ]): this {
      this.navigationPropertyFields = {
        ${ navigationProperties ( entity , service ) . join ( ',\n' ) }
      };
      return this;
    }` ; } function navigationProperties ( entity , service ) { return entity . navigationProperties . map ( ( navProp , i ) => navigationProperty ( navProp , service , i ) ) ; } function navigationProperty ( navProp , service , index ) { return `${ navProp . staticPropertyName }: new ${ linkClass ( navProp , service . oDataVersion ) }(
    '${ navProp . originalName }',
    this,
    linkedApis[${ index }]
  )` ; } function navigationPropertyTypes ( entity , service ) { return entity . navigationProperties . map ( navProp => navigationPropertyType ( navProp , entity , service ) ) ; } function navigationPropertyType ( navProp , entity , service ) { const toEntity = matchEntity ( navProp , service ) . className ; return [ documentationBlock `${ getStaticNavPropertyDescription ( navProp ) }` , `${ navProp . staticPropertyName }: ${ linkClass ( navProp , service . oDataVersion ) }<
      ${ entity . className }<DeSerializersT>,
      DeSerializersT,
      ${ toEntity }<DeSerializersT>
    >` ] . join ( '\n' ) ; } function navigationPropertyApiTypes ( entity , service ) { return entity . navigationProperties . map ( navProp => navigationPropertyApiType ( navProp , service ) ) ; } function navigationPropertyApiType ( navProp , service ) { const toEntity = matchEntity ( navProp , service ) . className ; return `${ toEntity }Api<DeSerializersT>` ; }