import api from './client';

export const apiGetCalendarByDateDivision = async ({ user, date, division }: { user: string, date: string, division: string }) => {
   const response = await api.get(`mobile/calendar?user=${user}&date=${date}&division=${division}`);
   return response.data;
};

export const apiGetIndicatorCalendar = async ({ user, date, division }: { user: string, date: string, division: string }) => {
   const response = await api.get(`mobile/calendar/indicator?user=${user}&date=${date}&division=${division}`);
   return response.data;
};

export const apiGetCalendarOne = async ({ user, id, cat }: { user: string, id: string, cat: 'data' | 'member' }) => {
   const response = await api.get(`mobile/calendar/${id}?user=${user}&cat=${cat}`);
   return response.data;
};

export const apiGetCalendarHistory = async ({ user, search, division, page }: { user: string, search: string, division: string, page?: number }) => {
   const response = await api.get(`mobile/calendar/history?user=${user}&search=${search}&division=${division}&page=${page}`);
   return response.data;
};

export const apiCreateCalendar = async ({ data }: { data: { idDivision: string, title: string, desc: string, timeStart: string, timeEnd: string, dateStart: string, repeatEventTyper: string, repeatValue: string, linkMeet: string, member: any[], user: string } }) => {
   const response = await api.post(`/mobile/calendar`, data)
   return response.data;
};

export const apiUpdateCalendar = async ({ data, id }: { data: { title: string, desc: string, timeStart: string, timeEnd: string, dateStart: string, repeatEventTyper: string, repeatValue: number, linkMeet: string, user: string }, id: string }) => {
   const response = await api.put(`/mobile/calendar/${id}`, data)
   return response.data;
};

export const apiDeleteCalendar = async (data: { user: string }, id: string) => {
   const response = await api.delete(`/mobile/calendar/${id}`, { data })
   return response.data
};

export const apiAddMemberCalendar = async ({ data, id }: { data: { user: string, member: any[] }, id: string }) => {
   const response = await api.post(`/mobile/calendar/${id}/member`, data)
   return response.data;
};

export const apiDeleteCalendarMember = async (data: { user: string, idUser: string }, id: string) => {
   const response = await api.delete(`/mobile/calendar/${id}/member`, { data })
   return response.data
};

export const apiGetVillageCalendarByDate = async ({ user, date }: { user: string, date: string }) => {
   const response = await api.get(`mobile/village-calendar?user=${user}&date=${date}`);
   return response.data;
};

export const apiGetVillageCalendarIndicator = async ({ user, date }: { user: string, date: string }) => {
   const response = await api.get(`mobile/village-calendar/indicator?user=${user}&date=${date}`);
   return response.data;
};
