//운영 서비스 관리 - 신고내역 api 연결

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

// 신고내역 전체 조회
export const ReportTotalView = async (token, startDate, endDate) => {
	try {
		const res = await Axios.get(`/api/v1/report/total?start_dt=${startDate}&end_dt=${endDate}`, {
			headers: { Authorization: `Bearer ${token}` },
		});
		return res.data.data;
	} catch (e) {
		if (e instanceof Error) {
			throw new Error('ReportTotalView', e);
		}
	}
};

// 신고내역 리스트 조회
export const ReportListView = async (token, startDate, endDate, reportType, status, searchType, searchKey, order, size, currentPage) => {
	try {
		const res = await Axios.get(
			`/api/v1/report/list?start_dt=${startDate}&end_dt=${endDate}&report_type=${reportType}&orderby=${order}&page_no=${currentPage}&page_size=${size}&status=${status}&search_type=${searchType}&search_key=${searchKey}`,
			{
				headers: { Authorization: `Bearer ${token}` },
			},
		);
		return res.data.data;
	} catch (e) {
		if (e instanceof Error) {
			throw new Error('ReportListView', e);
		}
	}
};
// 신고내역 상세조회
export const ReportListDetailView = async (token, pk, sk) => {
	try {
		const res = await Axios.get(`/api/v1/report/report-detail?pk=${pk}&sk=${sk}`, {
			headers: { Authorization: `Bearer ${token}` },
		});
		return res.data.data.report;
	} catch (e) {
		if (e instanceof Error) {
			throw new Error('ReportListDetailView', e);
		}
	}
};

// 신고내역 답변 작성
export const RepostReplyMessage = async (token, params) => {
	try {
		const res = await Axios.post('/api/v1/report/reply', params, {
			headers: { Authorization: `Bearer ${token}` },
		});
		return res;
	} catch (e) {
		if (e instanceof Error) {
			throw new Error('RepostReplyMessage Error', e);
		}
	}
};

// 신고내역 답변 조회
export const ReportReplyDetail = async (token, pk, sk) => {
	try {
		const res = await Axios.get(`/api/v1/report/reply-detail?pk=${pk}&sk=${sk}`, {
			headers: { Authorization: `Bearer ${token}` },
		});
		return res.data.data.reply;
	} catch (e) {
		if (e instanceof Error) {
			throw new Error('ReportReplyDetail', e);
		}
	}
};
