//운영 정보 관리 - 유저 조회 api 연결

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

// 유저 조회
export const UserView = async (token, searchType, searchKey) => {
	try {
		const res = await Axios.get(
			`/api/v1/users/find-users?
			search_type=${searchType ? searchType : 'NAME'}
			&search_key=${searchKey ? searchKey : ''}`,
			{ headers: { Authorization: `Bearer ${token}` } },
		);

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

// 기본 정보 조회
export const UserInfoView = async (token, guid) => {
	try {
		const res = await Axios.get(`/api/v1/users/basicinfo?guid=${guid}`, {
			headers: { Authorization: `Bearer ${token}` },
		});

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

// 닉네임 변경
export const UserChangeNickName = async (token, params) => {
	try {
		const res = await Axios.put('/api/v1/users/change-nickname', params, {
			headers: { Authorization: `Bearer ${token}` },
		});

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

// GM 권한 변경
export const UserChangeAdminLevel = async (token, params) => {
	try {
		const res = await Axios.put('/api/v1/users/change-level', params, {
			headers: { Authorization: `Bearer ${token}` },
		});

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

// 아바타 조회
export const UserAvatarView = async (token, guid) => {
	try {
		const res = await Axios.get(`/api/v1/users/avatarinfo?guid=${guid}`, {
			headers: { Authorization: `Bearer ${token}` },
		});

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

// 의상 조회
export const UserClothView = async (token, guid) => {
	try {
		const res = await Axios.get(`/api/v1/users/clothinfo?guid=${guid}`, {
			headers: { Authorization: `Bearer ${token}` },
		});

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

// 도구 조회
export const UserToolView = async (token, guid) => {
	try {
		const res = await Axios.get(`/api/v1/users/toolslot?guid=${guid}`, {
			headers: { Authorization: `Bearer ${token}` },
		});

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

// 인벤토리 조회
export const UserInventoryView = async (token, guid) => {
	try {
		const res = await Axios.get(`/api/v1/users/inventory?guid=${guid}`, {
			headers: { Authorization: `Bearer ${token}` },
		});

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

// 인벤토리 아이템 삭제
export const UserInventoryItemDelete = async (token, params) => {
	try {
		const res = await Axios.delete(`/api/v1/users/inventory/delete/item`, {
			headers: { Authorization: `Bearer ${token}` },
			data: params,
		});

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

// 타투 조회
export const UserTattooView = async (token, guid) => {
	try {
		const res = await Axios.get(`/api/v1/users/tattoo?guid=${guid}`, {
			headers: { Authorization: `Bearer ${token}` },
		});

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

// 퀘스트 조회
export const UserQuestView = async (token, guid) => {
	try {
		const res = await Axios.get(`/api/v1/users/quest?guid=${guid}`, {
			headers: { Authorization: `Bearer ${token}` },
		});

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

// 친구목록 조회
export const UserFriendListView = async (token, guid) => {
	try {
		const res = await Axios.get(`/api/v1/users/friendlist?guid=${guid}`, {
			headers: { Authorization: `Bearer ${token}` },
		});

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

// 우편 조회
export const UserMailView = async (token, guid, option) => {
	try {
		const res = await Axios.get(`/api/v1/users/mail?guid=${guid}&type=${option}`, {
			headers: { Authorization: `Bearer ${token}` },
		});

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

// 우편 삭제
export const UserMailDelete = async (token, params) => {
	try {
		const res = await Axios.delete(`/api/v1/users/mail/delete`, {
			headers: { Authorization: `Bearer ${token}` },
			data: params,
		});

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

// 우편 아이템 삭제
export const UserMailItemDelete = async (token, params) => {
	try {
		const res = await Axios.delete(`/api/v1/users/mail/delete/item`, {
			headers: { Authorization: `Bearer ${token}` },
			data: params,
		});

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

// 유저 우편 상세 정보 조회
export const UserMailDetailView = async (token, id) => {
	try {
		const res = await Axios.get(`/api/v1/users/mail/${id}}`, {
			headers: { Authorization: `Bearer ${token}` },
		});

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

// 마이홈 조회
export const UserMyhomeView = async (token, guid) => {
	try {
		const res = await Axios.get(`/api/v1/users/myhome?guid=${guid}`, {
			headers: { Authorization: `Bearer ${token}` },
		});

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