import { api } from './api'
import type { Expense } from '@/types/expense'

// Types for cost summary responses (would need to be added to types if not already present)
export interface ListCostSummary {
    list_id: number
    list_name: string
    total_list_cost: string
    num_participating_users: number
    equal_share_per_user: string
    user_balances: Array<{
        user_id: number
        user_identifier: string
        items_added_value: string
        amount_due: string
        balance: string
    }>
    expense_exists: boolean
    expense_id?: number
    calculated_at: string
}

export interface GroupBalanceSummary {
    group_id: number
    overall_total_expenses: string
    user_balances: Array<{
        user_id: number
        user_name: string
        total_paid: string
        total_owed: string
        net_balance: string
    }>
    suggested_settlements: Array<{
        from_user_id: number
        from_user_identifier: string
        to_user_id: number
        to_user_identifier: string
        amount: string
    }>
    calculated_at: string
}

export const costService = {
    // List Cost Summary operations
    async getListCostSummary(listId: number): Promise<ListCostSummary> {
        const response = await api.get(`/costs/lists/${listId}/cost-summary`)
        return response.data
    },

    async generateExpenseFromListSummary(listId: number): Promise<Expense> {
        const response = await api.post(`/costs/lists/${listId}/cost-summary`)
        return response.data
    },

    // Group Balance Summary operations
    async getGroupBalanceSummary(groupId: number): Promise<GroupBalanceSummary> {
        const response = await api.get(`/costs/groups/${groupId}/balance-summary`)
        return response.data
    },
} 