import{get as n}from"@clevercloud/client/esm/api/v2/application.js";import{getInvoice as i,getAllInvoices as e,getPriceSystem as t}from"@clevercloud/client/esm/api/v4/billing.js";import{addOauthHeader as o}from"@clevercloud/client/esm/oauth.js";import{prefixUrl as r}from"@clevercloud/client/esm/prefix-url.js";import{ONE_DAY as a}from"@clevercloud/client/esm/with-cache.js";import{sendToApi as c}from"./send-to-api.js";import{asyncMap as s}from"./utils.js";function u({apiConfig:i,signal:e,ownerId:t,appId:o}){return n({id:t,appId:o}).then(c({apiConfig:i,signal:e}))}async function l({apiConfig:n,signal:e,ownerId:t,invoiceNumber:o}){return i({id:t,invoiceNumber:o,type:""}).then(c({apiConfig:n,signal:e})).then((i=>d(n,t,i)))}async function m({apiConfig:n,signal:e,ownerId:t,invoiceNumber:o}){return i({id:t,invoiceNumber:o,type:".html"}).then(c({apiConfig:n,signal:e}))}async function p({apiConfig:n,signal:i,ownerId:t}){return e({id:t,since:"2010-08-01T00:00:00.000Z"}).then(c({apiConfig:n,signal:i})).then((i=>s(i,(async i=>d(n,t,i)))))}async function d(n,i,e){return{number:e.invoice_number,emissionDate:e.emission_date,type:e.type||"INVOICE",status:e.status,total:{amount:e.total_tax.amount+e.total_tax_excluded.amount,currency:e.total_tax_excluded.currency},downloadUrl:await f(n,i,e.invoice_number),paymentUrl:g(i,e.invoice_number)}}function f(n,e,t){return i({id:e,invoiceNumber:t,type:".pdf"}).then(r(n.API_HOST)).then(o(n)).then((n=>{const i=new URL(n.url);return i.searchParams.set("authorization",btoa(n.headers.authorization)),i.toString()}))}function g(n,i){return null==n||n.startsWith("user_")?`/users/me/invoices/${i}`:`/organisations/${n}/invoices/${i}`}function h({apiConfig:n,signal:i,zoneId:e,currency:o}){return t({zone_id:e,currency:o}).then(c({apiConfig:n,signal:i,cacheDelay:a}))}export{p as fetchAllInvoices,u as fetchApp,l as fetchInvoice,m as fetchInvoiceHtml,h as fetchPriceSystem};
//# sourceMappingURL=api-helpers.js.map
