import { api } from "@/lib/api-client";

export interface PaymentRecord {
  id: number;
  ref: string;
  student_id: number | null;
  student_name: string;
  course_id: number | null;
  course_name: string;
  product_name: string;
  amount: number;
  after_discount_amount: number;
  currency: string;
  state: string;
  paid: boolean;
  date: string;
  type: string;
  invoice_id: number | null;
  invoice_number: string;
  payment_state: string;
}

export interface PaymentTotals {
  count: number;
  paid: number;
  unpaid: number;
  amount: number;
}

export interface PaymentListResponse {
  data: PaymentRecord[];
  items: PaymentRecord[];
  total: number;
  totals: PaymentTotals;
}

export interface PaymobOrder {
  id: string | number;
  status: string;
  user: string;
  email: string;
  amount: number;
}

export interface PaymobListResponse {
  data: PaymobOrder[];
  items: PaymobOrder[];
  total: number;
  message?: string;
}

export const paymentsService = {
  async list(params?: { status?: string; paid?: string; student_id?: number }) {
    return api.get<PaymentListResponse>(
      "/payment-records",
      params as Record<string, string | number | boolean | undefined>,
    );
  },

  async paymobOrders() {
    return api.get<PaymobListResponse>("/paymob-orders");
  },
};
