import { api } from "@/lib/api-client";
import type { Package, Payment, Discount, PaginatedResponse, PaginationParams, ApiSuccessResponse } from "@/types";

export const subscriptionsService = {
  async listPackages(): Promise<Package[]> {
    return api.get<Package[]>("/packages");
  },

  async listPayments(params?: PaginationParams): Promise<PaginatedResponse<Payment>> {
    return api.get<PaginatedResponse<Payment>>("/payments", params as Record<string, string | number | boolean | undefined>);
  },

  async createStripeCheckout(data: { package_id: number; discount_code?: string }): Promise<{ checkout_url: string }> {
    return api.post("/stripe/checkout", data);
  },

  async createPaypalCheckout(data: { package_id: number; discount_code?: string }): Promise<{ approval_url: string }> {
    return api.post("/paypal/checkout", data);
  },

  async createPaymobCheckout(data: { package_id: number; discount_code?: string }): Promise<{ payment_url: string }> {
    return api.post("/paymob/checkout", data);
  },

  async listDiscounts(params?: PaginationParams): Promise<PaginatedResponse<Discount>> {
    return api.get<PaginatedResponse<Discount>>("/discounts", params as Record<string, string | number | boolean | undefined>);
  },

  async createDiscount(data: Partial<Discount>): Promise<Discount> {
    return api.post<Discount>("/discounts", data);
  },

  async deleteDiscount(id: number): Promise<ApiSuccessResponse> {
    return api.delete<ApiSuccessResponse>(`/discounts/${id}`);
  },
};
