import { authFetch } from '../../../utils/authFetch' export type MatrixStateData = { matrixInstanceId: string | number wasActive: boolean isActive: boolean status: 'deactivated' | 'already_inactive' | 'activated' | 'already_active' } type MatrixStateResponse = { success: boolean data?: MatrixStateData message?: string } const baseUrl = (process.env.NEXT_PUBLIC_API_BASE_URL || '').replace(/\/+$/, '') async function patch(endpoint: string) { const url = `${baseUrl}${endpoint}` const res = await authFetch(url, { method: 'PATCH', headers: { Accept: 'application/json' }, credentials: 'include' }) const ct = res.headers.get('content-type') || '' const raw = await res.text() const json: MatrixStateResponse | null = ct.includes('application/json') ? JSON.parse(raw) : null if (!res.ok || !json?.success) { const msg = json?.message || `Request failed: ${res.status}` throw new Error(msg) } return json.data! } export async function deactivateMatrix(id: string | number) { if (!id && id !== 0) throw new Error('matrix id required') return patch(`/api/admin/matrix/${id}/deactivate`) } export async function activateMatrix(id: string | number) { if (!id && id !== 0) throw new Error('matrix id required') // Assuming symmetrical endpoint; backend may expose this path. return patch(`/api/admin/matrix/${id}/activate`) }