/* eslint-disable @typescript-eslint/no-explicit-any */ import { AffixDetail, ASDetail, CharacterDetail, ConfigMaze, FreeSRJson, LightConeDetail, MocDetail, PFDetail, PSResponse, RelicDetail } from "@/types"; import axios from 'axios'; import { pSResponseSchema } from "@/zod"; export async function getConfigMazeApi(): Promise { try { const res = await axios.get( `/api/config-maze`, { headers: { 'Content-Type': 'application/json', }, } ); return res.data as ConfigMaze; } catch (error: unknown) { if (axios.isAxiosError(error)) { console.log(`Error: ${error.response?.status} - ${error.message}`); } else { console.log(`Unexpected error: ${String(error)}`); } return { Avatar: {}, MOC: {}, AS: {}, PF: {}, Stage: {}, }; } } export async function getMainAffixApi(): Promise>> { try { const res = await axios.get>>( `/api/main-affixes`, { headers: { 'Content-Type': 'application/json', }, } ); return res.data as Record>; } catch (error: unknown) { if (axios.isAxiosError(error)) { console.log(`Error: ${error.response?.status} - ${error.message}`); } else { console.log(`Unexpected error: ${String(error)}`); } return {}; } } export async function getSubAffixApi(): Promise>> { try { const res = await axios.get>>( `/api/sub-affixes`, { headers: { 'Content-Type': 'application/json', }, } ); return res.data as Record>; } catch (error: unknown) { if (axios.isAxiosError(error)) { console.log(`Error: ${error.response?.status} - ${error.message}`); } else { console.log(`Unexpected error: ${String(error)}`); } return {}; } } export async function fetchCharacterByIdNative(id: string, locale: string): Promise { try { const res = await axios.get(`/api/${locale}/characters/${id}`); return res.data; } catch (error) { console.error('Failed to fetch character:', error); return null; } } export async function fetchCharactersByIdsNative(ids: string[], locale: string): Promise> { try { const res = await axios.post>(`/api/${locale}/characters`, { charIds: ids }); return res.data; } catch (error) { console.error('Failed to fetch characters:', error); return {}; } } export async function fetchLightconeByIdNative(id: string, locale: string): Promise { try { const res = await axios.get(`/api/${locale}/lightcones/${id}`); return res.data; } catch (error) { console.error('Failed to fetch lightcone:', error); return null; } } export async function fetchLightconesByIdsNative(ids: string[], locale: string): Promise> { try { const res = await axios.post>(`/api/${locale}/lightcones`, { lightconeIds: ids }); return res.data; } catch (error) { console.error('Failed to fetch lightcones:', error); return {}; } } export async function fetchRelicByIdNative(id: string, locale: string): Promise { try { const res = await axios.get(`/api/${locale}/relics/${id}`); return res.data; } catch (error) { console.error('Failed to fetch relic:', error); return null; } } export async function fetchRelicsByIdsNative(ids: string[], locale: string): Promise> { try { const res = await axios.post>(`/api/${locale}/relics`, { relicIds: ids }); return res.data; } catch (error) { console.error('Failed to fetch relics:', error); return {}; } } export async function fetchASByIdsNative(ids: string[], locale: string): Promise | null> { try { const res = await axios.post>(`/api/${locale}/as`, { asIds: ids }); return res.data; } catch (error) { console.error('Failed to fetch AS:', error); return null; } } export async function fetchASByIdNative(ids: string, locale: string): Promise { try { const res = await axios.get(`/api/${locale}/as/${ids}`); return res.data; } catch (error) { console.error('Failed to fetch AS:', error); return null; } } export async function fetchPFByIdsNative(ids: string[], locale: string): Promise | null> { try { const res = await axios.post>(`/api/${locale}/pf`, { pfIds: ids }); return res.data; } catch (error) { console.error('Failed to fetch PF:', error); return null; } } export async function fetchPFByIdNative(ids: string, locale: string): Promise { try { const res = await axios.get(`/api/${locale}/pf/${ids}`); return res.data; } catch (error) { console.error('Failed to fetch PF:', error); return null; } } export async function fetchMOCByIdsNative(ids: string[], locale: string): Promise | null> { try { const res = await axios.post>(`/api/${locale}/moc`, { mocIds: ids }); return res.data; } catch (error) { console.error('Failed to fetch MOC:', error); return null; } } export async function fetchMOCByIdNative(ids: string, locale: string): Promise { try { const res = await axios.get(`/api/${locale}/moc/${ids}`); return res.data; } catch (error) { console.error('Failed to fetch MOC:', error); return null; } } export async function SendDataToServer(username: string, password: string, serverUrl: string, data: FreeSRJson | null): Promise { try { const response = await axios.post(`${serverUrl}`, { username, password, data }) const parsed = pSResponseSchema.safeParse(response.data) if (!parsed.success) { return "Invalid response schema"; } return parsed.data; } catch (error: any) { return error?.message || "Unknown error"; } } export async function SendDataThroughProxy({data}: {data: any}) { try { const response = await axios.post(`/api/proxy`, { ...data }) return response.data; } catch (error: any) { return error; } }