var i=(e,t,o)=>new Promise((s,l)=>{var f=r=>{try{c(o.next(r))}catch(d){l(d)}},u=r=>{try{c(o.throw(r))}catch(d){l(d)}},c=r=>r.done?s(r.value):Promise.resolve(r.value).then(f,u);c((o=o.apply(e,t)).next())});import{cb as w,bf as n}from"./bootstrap-Bqxdt4iG.js";const y=w("warehouses",{state:()=>({version:0}),getters:{isMockMode:()=>!1},actions:{getList(e){return i(this,null,function*(){var d,h;let t=n.from("warehouses").select("*",{count:"exact"});t=t.eq("isDelete",!1),e!=null&&e.code&&(t=t.ilike("code",`%${e.code}%`)),e!=null&&e.name&&(t=t.ilike("name",`%${e.name}%`)),t=e!=null&&e.sortBy?t.order(e.sortBy,{ascending:e.sortOrder!=="desc"}):t.order("createdAt",{ascending:!1});const o=(d=e==null?void 0:e.page)!=null?d:1,s=(h=e==null?void 0:e.pageSize)!=null?h:10,l=(o-1)*s,f=l+s-1;t=t.range(l,f);const{data:u,error:c,count:r}=yield t;if(c)throw c;return{items:u!=null?u:[],total:r!=null?r:0,page:o,pageSize:s}})},getDetail(e){return i(this,null,function*(){const{data:t,error:o}=yield n.from("warehouses").select("*").eq("id",e).eq("isDelete",!1).single();if(o)throw o;return t})},create(e){return i(this,null,function*(){const{data:t,error:o}=yield n.from("warehouses").insert(e).select().single();if(o||!t)throw o!=null?o:new Error("Create failed");return this.version++,t})},update(e,t){return i(this,null,function*(){const{data:o,error:s}=yield n.from("warehouses").update(t).eq("id",e).select().single();if(s)throw s;return this.version++,o})},remove(e){return i(this,null,function*(){const{error:t}=yield n.from("warehouses").update({isDelete:!0}).eq("id",e);if(t)throw t;return this.version++,!0})},restore(e){return i(this,null,function*(){const{error:t}=yield n.from("warehouses").update({isDelete:!1}).eq("id",e);if(t)throw t;return this.version++,!0})},hardDelete(e){return i(this,null,function*(){const{error:t}=yield n.from("warehouses").delete().eq("id",e);if(t)throw t;return this.version++,!0})},fetchOptions(){return i(this,null,function*(){const{data:e,error:t}=yield n.from("warehouses").select("id, code, name").eq("isDelete",!1).order("code",{ascending:!0});if(t)throw t;return(e!=null?e:[]).map(o=>({label:`${o.code} - ${o.name}`,value:o.id}))})},invalidate(){this.version++}}});export{y as u};
