import http from "./http";

export const login = (payload) => http.post("/auth/login", payload);
export const register = (payload) => http.post("/auth/register", payload);
export const me = () => http.get("/auth/me");
export const logout = () => http.post("/auth/logout");

export const adminStats = () => http.get("/admin/stats");
export const adminUsers = (role) => http.get("/admin/users", { params: { role } });
export const adminCreateUser = (payload) => http.post("/admin/users", payload);
export const adminUpdateUser = (payload) => http.put("/admin/users", payload);
export const adminResetPassword = (id, password) => http.post(`/admin/users/${id}/reset-password`, null, { params: { password } });

export const eldersList = () => http.get("/admin/elders");
export const eldersCreate = (payload) => http.post("/admin/elders", payload);
export const eldersUpdate = (payload) => http.put("/admin/elders", payload);
export const eldersDelete = (id) => http.delete(`/admin/elders/${id}`);

export const schedulesByDate = (date) => http.get("/admin/schedules", { params: { date } });
export const schedulesByRange = (start, end) => http.get("/admin/schedules/range", { params: { start, end } });
export const scheduleCreate = (payload) => http.post("/admin/schedules", payload);
export const scheduleUpdate = (payload) => http.put("/admin/schedules", payload);
export const scheduleDelete = (id) => http.delete(`/admin/schedules/${id}`);

export const billsCreate = (payload) => http.post("/admin/bills", payload);
export const billsUpdate = (payload) => http.put("/admin/bills", payload);
export const billsDelete = (id) => http.delete(`/admin/bills/${id}`);
export const billsList = (elderId) => http.get("/admin/bills", { params: { elderId } });

export const feedbackList = () => http.get("/admin/feedback");
export const feedbackUpdate = (payload) => http.put("/admin/feedback", payload);

export const noticeCreate = (payload) => http.post("/admin/notices", payload);
export const noticeList = (role, userId) => http.get("/admin/notices", { params: Object.fromEntries(Object.entries({ role, userId }).filter(([, v]) => v != null)) });

export const nurseSchedules = (date) => http.get("/nurse/schedules", { params: { date } });
export const nurseSchedulesRange = (start, end) => http.get("/nurse/schedules/range", { params: { start, end } });
export const nurseCareCreate = (payload) => http.post("/nurse/care-records", payload);
export const nurseCareList = (elderId) => http.get("/nurse/care-records", { params: { elderId } });
export const nurseHealthCreate = (payload) => http.post("/nurse/health-records", payload);
export const nurseHealthList = (elderId) => http.get("/nurse/health-records", { params: { elderId } });
export const nurseHandoverCreate = (payload) => http.post("/nurse/handovers", payload);
export const nurseHandoverList = () => http.get("/nurse/handovers");
export const nurseNoticeList = () => http.get("/nurse/notices");

export const familyElders = () => http.get("/family/elders");
export const familyCareList = (elderId) => http.get("/family/care-records", { params: { elderId } });
export const familyHealthList = (elderId) => http.get("/family/health-records", { params: { elderId } });
export const familyBills = (elderId) => http.get("/family/bills", { params: { elderId } });
export const familyPay = (id, payload) => http.post(`/family/bills/${id}/pay`, payload);
export const familyFeedback = (payload) => http.post("/family/feedback", payload);
export const familyFeedbackList = () => http.get("/family/feedback");
export const familyNoticeList = () => http.get("/family/notices");

export const uploadFile = (file) => {
  const form = new FormData();
  form.append("file", file);
  return http.post("/files/upload", form, { headers: { "Content-Type": "multipart/form-data" } });
};
