//사용자 관리 - 로그조회 api 연결

import { Axios } from '../utils';

export const LogViewList = async (token, searchType, searchKey, historyType, startDt, endDt, orderBy, size, currentPage) => {
	try {
		const res = await Axios.get(
			`/api/v1/history/list?search_type=${searchType ? searchType : 'NAME'}&search_key=${searchKey ? searchKey : ''}&history_type=${historyType ? historyType : ''}&start_dt=${
				startDt ? startDt : ''
			}&end_dt=${endDt ? endDt : ''}&orderby=${orderBy ? orderBy : 'DESC'}&page_no=${currentPage}&page_size=${size}`,
			{
				headers: { Authorization: `Bearer ${token}` },
			},
		);

		return res.data.data;
	} catch (e) {
		if (e instanceof Error) {
			throw new Error('LogViewList Error', e);
		}
	}
};

export const LogviewDetail = async (token, id) => {
	try {
		const res = await Axios.get(`/api/v1/history/detail/${id}`, {
			headers: { Authorization: `Bearer ${token}` },
		});

		return res.data.data.content;
	} catch (e) {
		if (e instanceof Error) {
			throw new Error('LogViewDetail', e);
		}
	}
};
