import{get as e}from"@clevercloud/client/esm/api/v2/application.js";import{getInvoice as n,getAllInvoices as i}from"@clevercloud/client/esm/api/v4/billing.js";import{addOauthHeader as t}from"@clevercloud/client/esm/oauth.js";import{pickNonNull as r}from"@clevercloud/client/esm/pick-non-null.js";import{prefixUrl as o}from"@clevercloud/client/esm/prefix-url.js";import{ONE_DAY as a}from"@clevercloud/client/esm/with-cache.js";import{sendToApi as s}from"./send-to-api.js";import{asyncMap as c}from"./utils.js";function u({apiConfig:n,signal:i,ownerId:t,appId:r}){return e({id:t,appId:r}).then(s({apiConfig:n,signal:i}))}async function l({apiConfig:e,signal:i,ownerId:t,invoiceNumber:r}){return n({id:t,invoiceNumber:r,type:""}).then(s({apiConfig:e,signal:i})).then((n=>d(e,t,n)))}async function p({apiConfig:e,signal:i,ownerId:t,invoiceNumber:r}){return n({id:t,invoiceNumber:r,type:".html"}).then(s({apiConfig:e,signal:i}))}async function m({apiConfig:e,signal:n,ownerId:t}){return i({id:t,since:"2010-08-01T00:00:00.000Z"}).then(s({apiConfig:e,signal:n})).then((n=>c(n,(async n=>d(e,t,n)))))}async function d(e,n,i){return{number:i.invoice_number,emissionDate:i.emission_date,type:i.type||"INVOICE",status:i.status,total:{amount:i.total_tax.amount+i.total_tax_excluded.amount,currency:i.total_tax_excluded.currency},downloadUrl:await f(e,n,i.invoice_number),paymentUrl:g(n,i.invoice_number)}}function f(e,i,r){return n({id:i,invoiceNumber:r,type:".pdf"}).then(o(e.API_HOST)).then(t(e)).then((e=>{const n=new URL(e.url);return n.searchParams.set("authorization",btoa(e.headers.Authorization)),n.toString()}))}function g(e,n){return null==e||e.startsWith("user_")?`/users/me/invoices/${n}`:`/organisations/${e}/invoices/${n}`}function h(e){return Promise.resolve({method:"get",url:"/v4/billing/price-system",headers:{Accept:"application/json"},queryParams:r(e,["zone_id","currency"])})}function v({apiConfig:e,signal:n,zoneId:i,currency:t}){return h({zone_id:i,currency:t}).then(s({apiConfig:e,signal:n,cacheDelay:a}))}function y(e){return Promise.resolve({method:"get",url:`/v4/saas/grafana/${e.id}`,headers:{Accept:"application/json"}})}function j(e){return Promise.resolve({method:"post",url:`/v4/saas/grafana/${e.id}`,headers:{Accept:"application/json"}})}function _(e){return Promise.resolve({method:"delete",url:`/v4/saas/grafana/${e.id}`,headers:{Accept:"application/json"}})}function b(e){return Promise.resolve({method:"post",url:`/v4/saas/grafana/${e.id}/reset`,headers:{Accept:"application/json"}})}function C({id:e,appId:n}){return Promise.resolve({method:"get",url:`/v4/stats/organisations/${e}/resources/${n}/metrics?interval=P1D&span=PT1H&only=cpu&only=mem`,headers:{Accept:"application/json"}})}export{j as createGrafanaOrganisation,_ as deleteGrafanaOrganisation,m as fetchAllInvoices,u as fetchApp,l as fetchInvoice,p as fetchInvoiceHtml,v as fetchPriceSystem,C as getAppMetrics,y as getGrafanaOrganisation,h as getPriceSystem,b as resetGrafanaOrganisation};
//# sourceMappingURL=api-helpers.js.map
