// Re-export types from shared types package
export type {
  BillingInterval,
  PriceWithProduct,
  StripeApiPrice,
  StripeApiProduct,
  StripeApiSubscription,
  StripeCustomer,
  StripePrice,
  StripeProduct,
  StripeSubscription,
  SubscriptionStatus,
  SubscriptionWithDetails,
  UserSubscriptionStatus,
} from "@xtablo/shared-types";

// Import types for use in helper functions
import type { BillingInterval, SubscriptionStatus } from "@xtablo/shared-types";

// Helper type guards
export function isActiveSubscription(status: SubscriptionStatus): boolean {
  return status === "active" || status === "trialing";
}

export function isPastDue(status: SubscriptionStatus): boolean {
  return status === "past_due";
}

export function isCanceled(status: SubscriptionStatus): boolean {
  return status === "canceled";
}

// Format currency helper
export function formatPrice(amount: number, currency = "eur"): string {
  return new Intl.NumberFormat("fr-FR", {
    style: "currency",
    currency: currency.toUpperCase(),
    minimumFractionDigits: 0,
  }).format(amount / 100);
}

// Format interval helper
export function formatInterval(interval: BillingInterval | null, count = 1): string {
  if (!interval) return "";

  const intervals: Record<BillingInterval, string> = {
    day: count === 1 ? "jour" : "jours",
    week: count === 1 ? "semaine" : "semaines",
    month: count === 1 ? "mois" : "mois",
    year: count === 1 ? "an" : "ans",
  };

  return count > 1 ? `${count} ${intervals[interval]}` : intervals[interval];
}

// Get subscription status display text
export function getSubscriptionStatusText(status: SubscriptionStatus): string {
  const statusTexts: Record<SubscriptionStatus, string> = {
    active: "Actif",
    trialing: "Période d'essai",
    past_due: "Paiement en retard",
    canceled: "Annulé",
    unpaid: "Impayé",
    incomplete: "Incomplet",
    incomplete_expired: "Expiré",
  };

  return statusTexts[status] || status;
}

// Get subscription status color for UI
export function getSubscriptionStatusColor(status: SubscriptionStatus): string {
  const colors: Record<SubscriptionStatus, string> = {
    active: "green",
    trialing: "blue",
    past_due: "orange",
    canceled: "gray",
    unpaid: "red",
    incomplete: "yellow",
    incomplete_expired: "red",
  };

  return colors[status] || "gray";
}
