import{l as s,w as a,m as U,u as x,k as H,n as c,o as p,t as u}from"./index-Db-xuq0b.js";const i={getAll:e=>s.get("/position-types",{headers:a(),params:e}),getById:e=>s.get(`/position-types/${e}`,{headers:a()}),getByUnitId:(e,o)=>s.get(`/position-types/list/${e}`,{headers:a(),params:o}),getCommonTypesById:(e,o)=>s.get(`/position-types/list-with-commons/${e}`,{headers:a(),params:o}),create:e=>s.post("/position-types",e,{headers:a()}),update:(e,o)=>s.put(`/position-types/${e}`,o,{headers:a()}),updateFromto:(e,o)=>s.patch(`/position-types/${e}/migrate-position-from/${o}`),updateByPostion:(e,o)=>s.patch(`/position-types/${e}/migrate-position-by-position`,o),delete:e=>s.delete(`/position-types/${e}`,{headers:a()})},I=({id:e,params:o={take:1e3,skip:0,orderBy:"createdAt:Desc"},unitId:n}={})=>{const r=U(),{t:g}=x(),{handleError:m}=H(g),{data:d,isLoading:h,isError:q,refetch:P}=c({queryKey:["position-types",o],queryFn:()=>i.getAll(o).then(t=>t.data)}),{data:T,isLoading:E,isError:F,refetch:K}=c({queryKey:["position-type",e],queryFn:()=>i.getById(e).then(t=>t.data),enabled:!!e}),{data:f,isLoading:v,isError:B,refetch:Q}=c({queryKey:["position-type",n,o],queryFn:async()=>n?(await i.getByUnitId(n,o)).data:void 0,enabled:!!n}),{data:l,isLoading:S,isError:$,refetch:C}=c({queryKey:["position-types-common",n,o],queryFn:async()=>n?(await i.getCommonTypesById(n,o)).data:void 0,enabled:!!n}),L=p({mutationFn:t=>i.create(t),onSuccess:()=>{u.success("Position type created"),r.invalidateQueries({queryKey:["position-types"]})},onError:t=>{m(t)}}),w=p({mutationFn:({id:t,data:y})=>i.update(t,y),onSuccess:()=>{u.success("Position type updated"),r.invalidateQueries({queryKey:["position-types"]}),r.invalidateQueries({queryKey:["position-type",e]})},onError:()=>{}}),b=p({mutationFn:({toId:t,fromId:y})=>i.updateFromto(t,y),onSuccess:()=>{u.success("Position type migration updated"),r.invalidateQueries({queryKey:["position-types-to"]}),r.invalidateQueries({queryKey:["position-type",e]})},onError:()=>{}}),k=p({mutationFn:({id:t,data:y})=>i.updateByPostion(t,y),onSuccess:()=>{u.success("Position type migration updated"),r.invalidateQueries({queryKey:["position-types-migration"]}),r.invalidateQueries({queryKey:["position-type",e]})},onError:()=>{}}),A=p({mutationFn:t=>i.delete(t),onSuccess:()=>{u.success("Position type deleted"),r.invalidateQueries({queryKey:["position-types"]})},onError:t=>{m(t)}});return{positionTypes:(d==null?void 0:d.items)??[],positionTypeResponse:d,isLoading:h,isError:q,refetch:P,positionType:T,isLoadingSingle:E,isErrorSingle:F,refetchSingle:K,createPositionType:L,updatePositionType:w,deletePositionType:A,positionTypeByUnitId:f,migratePositionsByPositions:k,updatePositionTypeFromTo:b,refetchPosition:Q,isErrorPosition:B,isLoadingPosition:v,commonPositionTypes:(l==null?void 0:l.items)??[],isLoadingCommonTypes:S,isErrorCommonTypes:$,refetchCommonTypes:C}};export{i as p,I as u};
