import { create } from "zustand"; import api from "../lib/api.ts"; export interface FeatureRequest { id: string; server_id: string; channel_id: string; author_id: string; title: string; description: string; status: "open" | "planned" | "done" | "rejected"; vote_count: number; voters: string[]; created_at: string; updated_at: string; } interface FeatureRequestStore { requestsByServer: Record; fetchRequests: (serverId: string) => Promise; createRequest: (serverId: string, title: string, description: string, channelId?: string) => Promise; vote: (serverId: string, requestId: string) => Promise; unvote: (serverId: string, requestId: string) => Promise; updateStatus: (serverId: string, requestId: string, status: string) => Promise; } export const useFeatureRequestStore = create((set, get) => ({ requestsByServer: {}, fetchRequests: async (serverId: string) => { const data = await api.get(`/servers/${serverId}/feature-requests`); set((s) => ({ requestsByServer: { ...s.requestsByServer, [serverId]: data }, })); }, createRequest: async (serverId, title, description, channelId) => { await api.post(`/servers/${serverId}/feature-requests`, { title, description, channel_id: channelId }); await get().fetchRequests(serverId); }, vote: async (serverId, requestId) => { await api.post(`/servers/${serverId}/feature-requests/${requestId}/vote`); await get().fetchRequests(serverId); }, unvote: async (serverId, requestId) => { await api.delete(`/servers/${serverId}/feature-requests/${requestId}/vote`); await get().fetchRequests(serverId); }, updateStatus: async (serverId, requestId, status) => { await api.patch(`/servers/${serverId}/feature-requests/${requestId}/status`, { status }); await get().fetchRequests(serverId); }, }));