"use strict";var U=Object.create;var c=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var h=Object.getPrototypeOf;var q=Object.prototype.hasOwnProperty;var d=(e,r)=>c(e,"name",{value:r,configurable:true});var y=(e,r)=>{for(var t in r)c(e,t,{get:r[t],enumerable:true})};var W=(e,r,t,s)=>{if(r&&typeof r==="object"||typeof r==="function"){for(let a of g(r))if(!q.call(e,a)&&a!==t)c(e,a,{get:()=>r[a],enumerable:!(s=R(r,a))||s.enumerable})}return e};var w=(e,r,t)=>(t=e!=null?U(h(e)):{},W(r||!e||!e.__esModule?c(t,"default",{value:e,enumerable:true}):t,e));var S=e=>W(c({},"__esModule",{value:true}),e);var L={};y(L,{createWorkspaceRequest:()=>E,deleteWorkspaceRequest:()=>f,getUserWorkspacesRequest:()=>m,resetApiRequests:()=>x,updateWorkspaceRequest:()=>T,workspaceApi:()=>u});module.exports=S(L);var l=require("lodash");var p=w(require("../../api/apiBase"));var n=require("../../api/utils/auth");var k=w(require("../../stores/lib/Request"));var i=w(require("./models/Workspace"));const o=require("../../preload-safe-debug")("Ferdium:feature:workspaces:api");const u={getUserWorkspaces:async()=>{const e=`${(0,p.default)()}/workspace`;o("getUserWorkspaces GET",e);const r=await(0,n.sendAuthRequest)(e,{method:"GET"});o("getUserWorkspaces RESULT",r);if(!r.ok){throw new Error("Couldn't getUserWorkspaces")}const t=await r.json();return t.map(s=>new i.default(s))},createWorkspace:async e=>{const r=`${(0,p.default)()}/workspace`;const t={method:"POST",body:JSON.stringify({name:e})};o("createWorkspace POST",r,t);const s=await(0,n.sendAuthRequest)(r,t);o("createWorkspace RESULT",s);if(!s.ok){throw new Error("Couldn't createWorkspace")}return new i.default(await s.json())},deleteWorkspace:async e=>{const r=`${(0,p.default)()}/workspace/${e.id}`;o("deleteWorkspace DELETE",r);const t=await(0,n.sendAuthRequest)(r,{method:"DELETE"});o("deleteWorkspace RESULT",t);if(!t.ok){throw new Error("Couldn't deleteWorkspace")}return true},updateWorkspace:async e=>{const r=`${(0,p.default)()}/workspace/${e.id}`;const t={method:"PUT",body:JSON.stringify((0,l.pick)(e,["name","services"]))};o("updateWorkspace UPDATE",r,t);const s=await(0,n.sendAuthRequest)(r,t);o("updateWorkspace RESULT",s);if(!s.ok){throw new Error("Couldn't updateWorkspace")}return new i.default(await s.json())}};const m=new k.default(u,"getUserWorkspaces");const E=new k.default(u,"createWorkspace");const f=new k.default(u,"deleteWorkspace");const T=new k.default(u,"updateWorkspace");const x=d(()=>{m.reset();E.reset();f.reset();T.reset()},"resetApiRequests");
