import { withHeaders } from "@/record-management/services/api/withHeaders"; import axiosInstance from "@/shared/services/axiosInstance"; import type { ListQuery, ListResponse, Location, LocationPayload, LocationType, LocationTypePayload, } from "@/user-management/dto/locations/location.type"; import { AxiosResponse } from "axios"; export const locationService = { list: ( params: ListQuery = {}, ): Promise>> => axiosInstance.get(`/locations`, { params, headers: withHeaders() }), create: (payload: LocationPayload): Promise> => axiosInstance.post(`/locations`, payload, { headers: withHeaders() }), update: ( id: string, payload: LocationPayload, ): Promise> => axiosInstance.put(`/locations/${id}`, payload, { headers: withHeaders() }), // Hard delete server-side — a location with children or unit clusters fails // on the foreign key rather than returning a tidy 409. remove: (id: string): Promise> => axiosInstance.delete(`/locations/${id}`, { headers: withHeaders() }), }; export const locationTypeService = { list: ( params: ListQuery = {}, ): Promise>> => axiosInstance.get(`/location-types`, { params, headers: withHeaders() }), create: ( payload: LocationTypePayload, ): Promise> => axiosInstance.post(`/location-types`, payload, { headers: withHeaders() }), update: ( id: string, payload: LocationTypePayload, ): Promise> => axiosInstance.put(`/location-types/${id}`, payload, { headers: withHeaders(), }), remove: (id: string): Promise> => axiosInstance.delete(`/location-types/${id}`, { headers: withHeaders() }), };