export interface BypassAccountResponse { id: number; username: string; displayName: string; organization: string | null; email: string | null; phone: string | null; status: string; accessStartDate: string | null; accessEndDate: string | null; createdAt: string; updatedAt: string; plainPassword: string | null; } export interface BypassAccountUpdateRequest { displayName?: string; organization?: string; email?: string; phone?: string; status?: string; accessStartDate?: string; accessEndDate?: string; } export interface BypassRequestResponse { id: number; applicantName: string; organization: string | null; purpose: string | null; email: string | null; phone: string | null; requestedAccessPeriod: string | null; status: string; reviewedBy: string | null; reviewedAt: string | null; rejectReason: string | null; accountId: number | null; accountUsername: string | null; createdAt: string; updatedAt: string; } export interface BypassRequestSubmitRequest { applicantName: string; organization: string; purpose: string; email: string; phone: string; requestedAccessPeriod: string; } export interface BypassRequestReviewRequest { reviewedBy: string; rejectReason?: string; accessStartDate?: string; accessEndDate?: string; } export interface PageResponse { content: T[]; totalElements: number; totalPages: number; number: number; size: number; } interface ApiResponse { success: boolean; message: string; data: T; } // BASE URL const BASE = '/snp-api/api/bypass-account'; // 헬퍼 함수 (bypassApi.ts 패턴과 동일) async function fetchJson(url: string): Promise { const res = await fetch(url); if (!res.ok) throw new Error(`API Error: ${res.status} ${res.statusText}`); return res.json(); } async function postJson(url: string, body?: unknown): Promise { const res = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: body != null ? JSON.stringify(body) : undefined, }); if (!res.ok) throw new Error(`API Error: ${res.status} ${res.statusText}`); return res.json(); } async function putJson(url: string, body?: unknown): Promise { const res = await fetch(url, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: body != null ? JSON.stringify(body) : undefined, }); if (!res.ok) throw new Error(`API Error: ${res.status} ${res.statusText}`); return res.json(); } async function deleteJson(url: string): Promise { const res = await fetch(url, { method: 'DELETE' }); if (!res.ok) throw new Error(`API Error: ${res.status} ${res.statusText}`); return res.json(); } export const bypassAccountApi = { // Accounts getAccounts: (status?: string, page = 0, size = 20) => { const params = new URLSearchParams({ page: String(page), size: String(size) }); if (status) params.set('status', status); return fetchJson>>(`${BASE}/accounts?${params}`); }, getAccount: (id: number) => fetchJson>(`${BASE}/accounts/${id}`), updateAccount: (id: number, data: BypassAccountUpdateRequest) => putJson>(`${BASE}/accounts/${id}`, data), deleteAccount: (id: number) => deleteJson>(`${BASE}/accounts/${id}`), resetPassword: (id: number) => postJson>(`${BASE}/accounts/${id}/reset-password`, {}), // Requests submitRequest: (data: BypassRequestSubmitRequest) => postJson>(`${BASE}/requests`, data), getRequests: (status?: string, page = 0, size = 20) => { const params = new URLSearchParams({ page: String(page), size: String(size) }); if (status) params.set('status', status); return fetchJson>>(`${BASE}/requests?${params}`); }, approveRequest: (id: number, data: BypassRequestReviewRequest) => postJson>(`${BASE}/requests/${id}/approve`, data), rejectRequest: (id: number, data: BypassRequestReviewRequest) => postJson>(`${BASE}/requests/${id}/reject`, data), };