import { accessApi } from "@cognite/sdk-core"; import { ConfigureAPI } from "../baseWellsClient"; import { WellMergeRulesAPI } from "./wellMergeRulesApi"; import { rethrowAsHttpError } from "../errorHandlingUtils"; import { LimitCursorRequest } from "src/client/customModels/limitCursorRequest"; import { DeleteWells, WellItems, WellSource, WellSourceItems, WellFilterRequest, WellWellheadViewItems, WellByIdsRequest, IdentifierItems, } from "src"; export class WellsAPI extends ConfigureAPI { public get mergeRules() { return accessApi(this.mergeRulesApi); } public set setMergeRules(api: WellMergeRulesAPI) { this.mergeRulesApi = api; } private mergeRulesApi?: WellMergeRulesAPI; public retrieveMultiple = async ( request: WellByIdsRequest | IdentifierItems ): Promise => { const path: string = this.getPath(`/wells/byids`); return await this.client .asyncPost(path, { data: request }) .then((response) => response.data) .catch((err) => { throw rethrowAsHttpError(err); }); }; public list = async (filter: WellFilterRequest): Promise => { const path = this.getPath("/wells/list"); return await this.client .asyncPost(path, { data: filter }) .then((response) => response.data) .catch((err) => { throw rethrowAsHttpError(err); }); }; public search = async (filter: WellFilterRequest): Promise => { const path = this.getPath("/wells/search"); return await this.client .asyncPost(path, { data: filter }) .then((response) => response.data) .catch((err) => { throw rethrowAsHttpError(err); }); }; public ingest = async (ingestions: WellSource[]): Promise => { const path: string = this.getPath(`/wells`); const ingestionItems: WellSourceItems = { items: ingestions }; return await this.client .asyncPost(path, { data: ingestionItems }) .then((response) => response.data) .catch((err) => { throw rethrowAsHttpError(err); }); }; public delete = async (deleteWells: DeleteWells) => { const path: string = this.getPath(`/wells/delete`); return await this.client .asyncPost(path, { data: deleteWells }) .then((response) => response.data) .catch((err) => { throw rethrowAsHttpError(err); }); }; public wellheads = async ( request: LimitCursorRequest = {} ): Promise => { const path: string = this.getPath(`/wells/wellheads`); return await this.client .asyncGet(path, { params: { limit: request.limit, cursor: request.cursor, }, }) .then((response) => response.data) .catch((err) => { throw rethrowAsHttpError(err); }); }; }