// ============================================================================
// Stripe Types for Supabase Integration
// ============================================================================

// Types matching what the RPC functions return (Stripe API objects)
export interface StripeApiSubscription {
  id: string;
  customer: string;
  user_id: string;
  status: string;
  items: unknown;
  cancel_at_period_end: boolean;
  current_period_start: number;
  current_period_end: number;
  created: number;
  canceled_at: number | null;
  trial_start: unknown;
  trial_end: unknown;
  metadata: Record<string, unknown>;
}

export interface StripeApiProduct {
  id: string;
  name: string;
  description: string | null;
  active: boolean;
  created: number;
  metadata: Record<string, unknown>;
}

export interface StripeApiPrice {
  id: string;
  product: string;
  active: boolean;
  currency: string;
  unit_amount: number;
  recurring: unknown;
  created: number;
  metadata: Record<string, unknown>;
}

export interface StripeCustomer {
  id: string;
  user_id: string;
  stripe_customer_id: string;
  email: string | null;
  created_at: string;
  updated_at: string;
}

export interface StripeSubscription {
  id: string;
  user_id: string;
  stripe_customer_id: string;
  status: SubscriptionStatus;
  price_id: string | null;
  quantity: number | null;
  cancel_at_period_end: boolean;
  current_period_start: string | null;
  current_period_end: string | null;
  created_at: string;
  updated_at: string;
  canceled_at: string | null;
  trial_end: string | null;
  trial_start: string | null;
}

export interface StripeProduct {
  id: string;
  active: boolean;
  name: string;
  description: string | null;
  image: string | null;
  metadata: Record<string, string | number | boolean> | null;
  created_at: string;
  updated_at: string;
}

export interface StripePrice {
  id: string;
  product_id: string;
  active: boolean;
  currency: string;
  unit_amount: number;
  interval: BillingInterval | null;
  interval_count: number | null;
  trial_period_days: number | null;
  metadata: Record<string, string | number | boolean> | null;
  created_at: string;
  updated_at: string;
}

export type SubscriptionStatus =
  | "active"
  | "trialing"
  | "past_due"
  | "canceled"
  | "unpaid"
  | "incomplete"
  | "incomplete_expired";

export type BillingInterval = "day" | "week" | "month" | "year";

export interface UserSubscriptionStatus {
  subscription_id: string;
  status: SubscriptionStatus;
  current_period_end: string;
  cancel_at_period_end: boolean;
  price_id: string;
  product_name: string;
}

export interface PriceWithProduct extends StripePrice {
  product: StripeProduct;
}

export interface SubscriptionWithDetails extends StripeSubscription {
  price: StripePrice;
  product: StripeProduct;
}
