//운영자 관리 - 칼리움 api 연결

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

// 칼리움 요청 리스트 조회
export const CaliumRequestView = async (token, content, status, startDate, endDate, order, size, currentPage) => {
	try {
		const res = await Axios.get(
			`/api/v1/calium/list?content=${content}&status=${status}&start_dt=${startDate}&end_dt=${endDate}&orderby=${order}&page_no=${currentPage}
			&page_size=${size}`,
			{
				headers: { Authorization: `Bearer ${token}` },
			},
		);

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

// 칼리움 상세보기
export const CaliumDetailView = async (token, id) => {
	try {
		const res = await Axios.get(`/api/v1/calium/detail/${id}`, {
			headers: { Authorization: `Bearer ${token}` },
		});

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

// 칼리움 요청 등록
export const CaliumRequestRegist = async (token, params) => {
	try {
		const res = await Axios.post(`/api/v1/calium`, params, {
			headers: { Authorization: `Bearer ${token}` },
		});

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

// 칼리움 충적
export const CaliumCharge = async (token, params) => {
	try {
		const res = await Axios.post(`/api/v1/calium/charge`, params, {
			headers: { Authorization: `Bearer ${token}` },
		});

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

// 칼리움 인출 가능 수량
export const CaliumLimitCount = async (token) => {
	try {
		const res = await Axios.get(`/api/v1/calium/limit`, {
			headers: { Authorization: `Bearer ${token}` },
		});

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