import type { ChannelResponse, GuildMemberResponse, GuildResponse, MessageResponse } from "~/types/interfaces"; export const useApi = () => { async function fetchGuilds(): Promise { return await fetchWithApi(`/guilds`); } async function fetchGuild(guildId: string): Promise { return await fetchWithApi(`/guilds/${guildId}`); } async function fetchChannels(guildId: string): Promise { return await fetchWithApi(`/guilds/${guildId}/channels`); } async function fetchChannel(channelId: string): Promise { return await fetchWithApi(`/channels/${channelId}`) } async function fetchMembers(guildId: string): Promise { return await fetchWithApi(`/guilds/${guildId}/members`); } async function fetchMember(guildId: string, memberId: string): Promise { return await fetchWithApi(`/guilds/${guildId}/members/${memberId}`); } async function fetchUsers() { return await fetchWithApi(`/users`); } async function fetchUser(userId: string) { return await fetchWithApi(`/users/${userId}`); } async function fetchMessages(channelId: string, options?: { amount?: number, offset?: number }): Promise { return await fetchWithApi(`/channels/${channelId}/messages`, { query: { amount: options?.amount ?? 100, offset: options?.offset ?? 0 } }); } async function fetchMessage(channelId: string, messageId: string): Promise { return await fetchWithApi(`/channels/${channelId}/messages/${messageId}`); } async function createGuild(name: string): Promise { return await fetchWithApi(`/guilds`, { method: "POST", body: { name } }); } async function joinGuild(invite: string): Promise { return await fetchWithApi(`/invites/${invite}`, { method: "POST" }) as GuildResponse; } return { fetchGuilds, fetchGuild, fetchChannels, fetchChannel, fetchMembers, fetchMember, fetchUsers, fetchUser, fetchMessages, fetchMessage, createGuild, joinGuild, } }