/** * Net Worth Service */ import {apiClient} from './client'; export interface Asset { id: string; name: string; type: 'CASH' | 'INVESTMENT' | 'PROPERTY' | 'VEHICLE' | 'OTHER'; value: number; createdAt?: string; updatedAt?: string; } export interface CreateAssetRequest { name: string; type: 'CASH' | 'INVESTMENT' | 'PROPERTY' | 'VEHICLE' | 'OTHER'; value: number; } export interface UpdateAssetRequest { name?: string; type?: 'CASH' | 'INVESTMENT' | 'PROPERTY' | 'VEHICLE' | 'OTHER'; value?: number; } export interface Liability { id: string; name: string; type: 'CREDIT_CARD' | 'LOAN' | 'MORTGAGE' | 'OTHER'; currentBalance: number; interestRate?: number; minimumPayment?: number; dueDate?: string; creditor?: string; notes?: string; createdAt?: string; updatedAt?: string; } export interface CreateLiabilityRequest { name: string; type: 'CREDIT_CARD' | 'LOAN' | 'MORTGAGE' | 'OTHER'; currentBalance: number; interestRate?: number; minimumPayment?: number; dueDate?: string; creditor?: string; notes?: string; } export interface UpdateLiabilityRequest { name?: string; type?: 'CREDIT_CARD' | 'LOAN' | 'MORTGAGE' | 'OTHER'; currentBalance?: number; interestRate?: number; minimumPayment?: number; dueDate?: string; creditor?: string; notes?: string; } export interface NetWorthSnapshot { id: string; date: string; totalAssets: number; totalLiabilities: number; netWorth: number; notes?: string; createdAt?: string; } export const assetService = { async getAll(): Promise<{assets: Asset[]}> { return apiClient.get<{assets: Asset[]}>('/assets'); }, async getById(id: string): Promise<{asset: Asset}> { return apiClient.get<{asset: Asset}>(`/assets/${id}`); }, async create(data: CreateAssetRequest): Promise<{asset: Asset}> { return apiClient.post<{asset: Asset}>('/assets', data); }, async update(id: string, data: UpdateAssetRequest): Promise<{asset: Asset}> { return apiClient.put<{asset: Asset}>(`/assets/${id}`, data); }, async delete(id: string): Promise { return apiClient.delete(`/assets/${id}`); }, }; export const liabilityService = { async getAll(): Promise<{liabilities: Liability[]}> { return apiClient.get<{liabilities: Liability[]}>('/liabilities'); }, async getById(id: string): Promise<{liability: Liability}> { return apiClient.get<{liability: Liability}>(`/liabilities/${id}`); }, async create(data: CreateLiabilityRequest): Promise<{liability: Liability}> { return apiClient.post<{liability: Liability}>('/liabilities', data); }, async update(id: string, data: UpdateLiabilityRequest): Promise<{liability: Liability}> { return apiClient.put<{liability: Liability}>(`/liabilities/${id}`, data); }, async delete(id: string): Promise { return apiClient.delete(`/liabilities/${id}`); }, }; export const snapshotService = { async getAll(): Promise<{snapshots: NetWorthSnapshot[]}> { return apiClient.get<{snapshots: NetWorthSnapshot[]}>('/networth/snapshots'); }, async getById(id: string): Promise<{snapshot: NetWorthSnapshot}> { return apiClient.get<{snapshot: NetWorthSnapshot}>(`/networth/snapshots/${id}`); }, async create(data: { date: string; totalAssets: number; totalLiabilities: number; netWorth: number; notes?: string; }): Promise<{snapshot: NetWorthSnapshot}> { return apiClient.post<{snapshot: NetWorthSnapshot}>('/networth/snapshots', data); }, async createFromCurrent(notes?: string): Promise<{snapshot: NetWorthSnapshot}> { return apiClient.post<{snapshot: NetWorthSnapshot}>('/networth/snapshots/record', {notes}); }, async delete(id: string): Promise { return apiClient.delete(`/networth/snapshots/${id}`); }, };