import { apiGet, apiPatch, apiPost } from "./axios"; import type { AxiosResponse } from "axios"; import type { ApiListResponse } from "../types/api"; export interface FinanceItem { id: string; study_id: string; site_id?: string | null; subject_id?: string | null; visit_id?: string | null; category: string; title: string; description?: string | null; currency: string; amount: number | string; occur_date: string; status: string; submitted_at?: string | null; approved_at?: string | null; rejected_at?: string | null; paid_at?: string | null; approver_id?: string | null; payer_id?: string | null; reject_reason?: string | null; created_by: string; created_at: string; updated_at?: string | null; } export interface FinanceSummary { total_amount: number | string; approved_amount: number | string; paid_amount: number | string; submitted_amount?: number | string; count_total: number; count_paid: number; } export const fetchFinanceItems = ( studyId: string, params?: Record ): Promise>> => apiGet(`/api/v1/studies/${studyId}/finance/items/`, { params }); export const fetchFinanceItem = (studyId: string, itemId: string) => apiGet(`/api/v1/studies/${studyId}/finance/items/${itemId}`); export const createFinanceItem = (studyId: string, payload: Record) => apiPost(`/api/v1/studies/${studyId}/finance/items`, payload); export const updateFinanceItem = (studyId: string, itemId: string, payload: Record) => apiPatch(`/api/v1/studies/${studyId}/finance/items/${itemId}`, payload); export const changeFinanceStatus = ( studyId: string, itemId: string, payload: { status: string; reject_reason?: string } ) => apiPost(`/api/v1/studies/${studyId}/finance/items/${itemId}/status`, payload); export const fetchFinanceSummary = (studyId: string, params?: Record) => apiGet>( `/api/v1/studies/${studyId}/finance/summary`, { params } );