import{logger as i}from"../../../../tools/notifiers/logger.js";function c(t){return async e=>{const o=e.get("devOnboardingAdapter");try{const{data:r,total:n}=await o.getApps();return e.json(r,200,{"X-Pagination-Total":n.toString(),"Cache-Control":"no-store"})}catch(r){return i.error(r.message,r),e.json({message:r.message},500)}}}function g(t){return async e=>{const o=await e.req.json();if(!o)return e.json({error:"Invalid request"},400);const r=e.get("devOnboardingAdapter");try{const n=await r.createApp(o);return e.json(n,201)}catch(n){return i.error(n.message,n),e.json({error:n.message},400)}}}function f(t){return async e=>{const o=await e.req.json(),r=e.req.param("id");if(!r)return e.json({error:"Not found"},404);if(!o||!r)return e.json({error:"Invalid request"},400);const n=decodeURI(r),d=e.get("devOnboardingAdapter");try{const a=await d.createCredential(n,o);return e.json(a,201)}catch(a){return i.error(a.message,a),e.json({error:a.message},400)}}}function m(t){return async e=>{const o=await e.req.json(),r=e.req.param("id"),n=e.req.param("credentialId");if(!r||!n)return e.json({error:"Not found"},404);if(!o)return e.json({error:"Invalid request"},400);const d=decodeURI(r),a=decodeURI(n),s=e.get("devOnboardingAdapter");try{const p=await s.updateCredential(d,a,o);return e.json(p,201)}catch(p){return i.error(p.message,p),e.json({error:p.message},400)}}}function l(t){return async e=>{const o=e.req.param("id"),r=e.req.param("credentialId");if(!o||!r)return e.json({error:"Not found"},404);const n=decodeURI(o),d=decodeURI(r),a=e.get("devOnboardingAdapter");try{const s=await a.deleteCredential(n,d);return e.json(s,201)}catch(s){return i.error(s.message,s),e.json({error:s.message},400)}}}function I(t){return async e=>{const o=e.req.param("id");if(!o)return e.json({error:"Not found"},404);const r=decodeURI(o),d=await e.get("devOnboardingAdapter").getApp(r);return e.json(d,200,{"Cache-Control":"no-store"})}}function j(t){return async e=>{const o=e.req.param("id");if(!o)return e.json({error:"Not found"},404);const r=decodeURI(o);return await e.get("devOnboardingAdapter").deleteApp(r),new Response(null,{status:204})}}function A(t){return async e=>{const o=e.req.param("id");if(!o)return e.json({error:"Not found"},404);const r=await e.req.json();if(!r)return e.json({error:"Invalid request"},400);const n=decodeURI(o),a=await e.get("devOnboardingAdapter").updateApp(n,r);return e.json(a,200)}}function q(){return async t=>{const e=t.req.param("id");if(!e)return t.json({error:"Not found"},404);const o=decodeURI(e),r=t.req.query(),n=t.req.queries(),d={size:r.size?Number(r.size):void 0,page:r.page?Number(r.page):void 0,fromDate:r.fromDate?Number(r.fromDate):void 0,toDate:r.toDate?Number(r.toDate):void 0,filters:{apis:n.api,statusCodes:n.statusCode?.map(Number),methods:n.method}},s=await t.get("devOnboardingAdapter").getAppLogs(o,d);return t.json(s,200,{"Cache-Control":"no-store"})}}function y(){return async t=>{const e=t.req.param("id"),o=t.req.param("logId");if(!e||!o)return t.json({error:"Not found"},404);const r=decodeURI(e),n=decodeURI(o),a=await t.get("devOnboardingAdapter").getAppLogDetails(r,n);return t.json(a,200)}}export{g as createApp,f as createCredential,j as deleteApp,l as deleteCredential,I as getApp,y as getLogDetails,q as getLogs,c as listApps,A as updateApp,m as updateCredential};
