import { AxiosRequestConfig } from 'axios' ; import { TPDProvider , TPDISearchParams } from './const' ; export interface TPDProviderInterface { getSearchPayload ( params ) : any ; getOrderPayload ( name , collectionId , items , params ) : any ; addSearchPagination ( requestConfig , count , viewtoken ) : void ; } export abstract class AbstractTPDProvider implements TPDProviderInterface { protected provider : TPDProvider ; public getProvider ( ) { return this . provider ; } public addSearchPagination ( requestConfig , count , viewtoken ) { let queryParams = { } ; if ( ! isNaN ( count ) ) { queryParams . count = count ; } if ( viewtoken ) { queryParams . viewtoken = viewtoken ; } requestConfig . params = queryParams ; } protected getCommonSearchParams ( params ) { const payload = { } ; payload [ 'provider' ] = this . provider ; if ( ! params . bbox && ! params . geometry ) { throw new Error ( 'Parameter bbox and/or geometry must be specified' ) ; } const bounds = { } ; if ( ! ! params . bbox ) { bounds . bbox = [ params . bbox . minX , params . bbox . minY , params . bbox . maxX , params . bbox . maxY ] ; bounds . properties = { crs : params . bbox . crs . opengisUrl , } ; } if ( ! ! params . geometry ) { if ( ! params . crs ) { throw new Error ( 'Parameter crs must be specified' ) ; } bounds . geometry = params . geometry ; bounds . properties = { crs : params . crs . opengisUrl , } ; } payload . bounds = bounds ; return payload ; } protected getAdditionalSearchParams ( params ) { return { } ; } public getSearchPayload ( params ) { const commonParams = this . getCommonSearchParams ( params ) ; const additionalParams = this . getAdditionalSearchParams ( params ) ; const payload = { ... commonParams , ... additionalParams } ; return payload ; } protected getAdditionalOrderParams ( items , params ) { return { } ; } public getOrderPayload ( name , collectionId , items , params ) { const payload = { } ; if ( ! ! name ) { payload . name = name ; } if ( ! ! collectionId ) { payload . collectionId = collectionId ; } payload . input = this . getAdditionalOrderParams ( items , params ) ; return payload ; } }