import{l as u,m as a,n as o,o as i,p as y,q as A,t as r}from"./index-C-gKvEDq.js";import{t as l}from"./api-utils-SNhvzubv.js";import{q as n}from"./query-keys-DGBjVswC.js";const s={getAllAccounts:async e=>{const{data:t}=await u.get(a.ACCOUNTS,{params:l(e)});return t||[]},getAccounts:async e=>{const{data:t}=await u.get(a.ACCOUNTS,{params:l(e)});return t},getAccount:async e=>{const{data:t}=await u.get(a.ACCOUNT_DETAIL(e));return t},createAccount:async e=>{const{data:t}=await u.post(a.ACCOUNTS,e);return t},updateAccount:async(e,t)=>{const{data:c}=await u.put(a.ACCOUNT_DETAIL(e),t);return c},patchAccount:async(e,t)=>{const{data:c}=await u.patch(a.ACCOUNT_DETAIL(e),t);return c},deleteAccount:async e=>{await u.delete(a.ACCOUNT_DETAIL(e))},getAccountHierarchy:async()=>{const{data:e}=await u.get(a.ACCOUNT_HIERARCHY);return e},getParentAccounts:async()=>{const{data:e}=await u.get(a.PARENT_ACCOUNTS);return e.data}};function g(e){return o({queryKey:n.accounts.list(JSON.stringify(e)),queryFn:()=>s.getAllAccounts(e),retry:1,staleTime:300*1e3})}function m(e){return o({queryKey:n.accounts.list(JSON.stringify(e)),queryFn:()=>s.getAccounts(e),retry:1,staleTime:300*1e3})}function p(e,t=!0){return o({queryKey:n.accounts.detail(e),queryFn:()=>s.getAccount(e),enabled:t&&!!e})}function f(){return o({queryKey:n.accounts.hierarchy(),queryFn:()=>s.getAccountHierarchy()})}function T(){return o({queryKey:n.accounts.parentAccounts(),queryFn:()=>s.getParentAccounts()})}function h(){const e=i();return y({mutationFn:t=>s.createAccount(t),onSuccess:()=>{e.invalidateQueries({queryKey:n.accounts.lists()}),e.invalidateQueries({queryKey:n.accounts.hierarchy()}),r.success("Account created successfully")},onError:t=>{const c=A(t);r.error(c,{duration:5e3})}})}function K(){const e=i();return y({mutationFn:({id:t,data:c})=>s.updateAccount(t,c),onSuccess:(t,c)=>{e.invalidateQueries({queryKey:n.accounts.lists()}),e.invalidateQueries({queryKey:n.accounts.detail(c.id)}),e.invalidateQueries({queryKey:n.accounts.hierarchy()}),r.success("Account updated successfully")},onError:t=>{const c=A(t);r.error(c,{duration:5e3})}})}function N(){const e=i();return y({mutationFn:({id:t,data:c})=>s.patchAccount(t,c),onSuccess:(t,c)=>{e.invalidateQueries({queryKey:n.accounts.lists()}),e.invalidateQueries({queryKey:n.accounts.detail(c.id)}),r.success("Account updated successfully")},onError:t=>{const c=A(t);r.error(c,{duration:5e3})}})}function E(){const e=i();return y({mutationFn:t=>s.deleteAccount(t),onSuccess:()=>{e.invalidateQueries({queryKey:n.accounts.lists()}),e.invalidateQueries({queryKey:n.accounts.hierarchy()}),r.success("Account deleted successfully")},onError:t=>{const c=A(t);r.error(c,{duration:5e3})}})}export{s as a,h as b,K as c,f as d,T as e,m as f,N as g,E as h,p as i,g as u};
