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 o}from"@clevercloud/client/esm/pick-non-null.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 s}from"./send-to-api.js";import{asyncMap as c}from"./utils.js";function l({apiConfig:n,signal:i,ownerId:t,appId:o}){return e({id:t,appId:o}).then(s({apiConfig:n,signal:i}))}async function u({apiConfig:e,signal:i,ownerId:t,invoiceNumber:o}){return n({id:t,invoiceNumber:o,type:""}).then(s({apiConfig:e,signal:i})).then((n=>d(e,t,n)))}async function p({apiConfig:e,signal:i,ownerId:t,invoiceNumber:o}){return n({id:t,invoiceNumber:o,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:h(n,i.invoice_number)}}function f(e,i,o){return n({id:i,invoiceNumber:o,type:".pdf"}).then(r(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 h(e,n){return null==e||e.startsWith("user_")?`/users/me/invoices/${n}`:`/organisations/${e}/invoices/${n}`}function v(e){return Promise.resolve({method:"get",url:"/v4/billing/price-system",headers:{Accept:"application/json"},queryParams:o(e,["zone_id"])})}function g({signal:e,zoneId:n}){return v({zone_id:n}).then(s({signal:e,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 I({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,l as fetchApp,u as fetchInvoice,p as fetchInvoiceHtml,g as fetchPriceSystem,I as getAppMetrics,y as getGrafanaOrganisation,v as getPriceSystem,b as resetGrafanaOrganisation};
//# sourceMappingURL=api-helpers.js.map
