import { ImportDeclarationStructure , StructureKind } from 'ts-morph' ; import { ODataVersion } from '@sap-cloud-sdk/util' ; import { complexTypeImportDeclarations , odataImportDeclaration , enumTypeImportDeclarations } from '../imports' ; import { VdmEntity , VdmServiceMetadata } from '../vdm-types' ; internal export function entityImportDeclarations ( entity , oDataVersion ) { return [ odataImportDeclaration ( [ 'Entity' , 'DefaultDeSerializers' , 'DeSerializers' , 'DeserializedType' ] , oDataVersion ) , ... complexTypeImportDeclarations ( entity . properties ) , ... enumTypeImportDeclarations ( entity . properties ) ] ; } internal export function otherEntityImports ( entity , service ) { return Array . from ( new Set ( entity . navigationProperties . map ( n => n . to ) ) ) . map ( to => { const matchedEntity = service . entities . find ( e => e . entitySetName === to ) ; if ( ! matchedEntity ) { throw Error ( `Failed to find the entity from the service: ${ JSON . stringify ( service ) } for entity ${ entity }` ) ; } return matchedEntity . className ; } ) . filter ( name => name !== entity . className ) . map ( name => otherEntityImport ( name ) ) ; } function otherEntityImport ( name ) { return { kind : StructureKind . ImportDeclaration , namedImports : [ name , `${ name }Type` ] , moduleSpecifier : `./${ name }` } ; }