import { api } from "@/src/lib/api/client"

export type StatsByStatus = {
  status: string
  count: number
  total_paid: number
}

export type StatsByMethod = {
  method: string
  count: number
  amount: number
}

export type MonthlyTrend = {
  month: string
  amount: number
  count: number
}

export type StatsByAction = {
  type: string
  count: number
}

export type TenantStats = {
  cases: {
    total: number
    overdue: number
    total_amount: number
    total_paid: number
    recovery_rate: number
    by_status: StatsByStatus[]
    by_priority: { priority: string; count: number }[]
  }
  payments: {
    by_method: StatsByMethod[]
    monthly_trend: MonthlyTrend[]
  }
  actions: {
    by_type: StatsByAction[]
  }
  promises: {
    pending: number
    kept: number
    broken: number
    cancelled: number
  }
}

export async function getTenantStats(): Promise<TenantStats> {
  return api.request<TenantStats>("stats/")
}
