// ─── Auth Types ──────────────────────────────────────────────────────────────

export interface User {
  id: number;
  first_name?: string;
  last_name?: string;
  email: string;
  user_type: 'super_admin' | 'app_user';
  email_verified_at?: string;
  profile_picture?: string;
  plan_type?: string;
  plan_date?: string;
  is_active: number;
  is_social?: string;
  phone_number?: string;
  created_at?: string;
  updated_at?: string;
  access_token?: string;
  is_new_user?: boolean;
  introduction_text?: string;
}

export interface AuthState {
  user: User | null;
  isAuthenticated: boolean;
  isLoading: boolean;
  error: string | null;
}

export interface LoginPayload {
  email: string;
  password: string;
  is_social: string;
  notification_token?: string;
  social_token?: string;
  social_name?: string;
}

export interface LoginResponse {
  success: boolean;
  code: number;
  message: string;
  data: User;
}

export interface ActivatePayload {
  token: string;
}

export interface ActivateResponse {
  success: boolean;
  code: number;
  message: string;
  data: User & { access_token: string };
}

// ─── Subscription Types ───────────────────────────────────────────────────────

export type SubscriptionStatus =
  | 'active'
  | 'trialing'
  | 'trial_expired'
  | 'cancelled'
  | 'expired'
  | 'none';

export interface Subscription {
  id?: number;
  status: SubscriptionStatus;
  plan_id?: number;
  plan_name?: string;
  stripe_customer_id?: string;
  stripe_subscription_id?: string;
  trial_start?: string;
  trial_end?: string;
  current_period_start?: string;
  current_period_end?: string;
  cancel_at_period_end: boolean;
  cancelled_at?: string;
  created_at?: string;
  next_plan_id?: number | null;
  next_plan_name?: string | null;
  next_plan_start_date?: string | null;
}

export interface SubscriptionState {
  subscription: Subscription | null;
  isLoading: boolean;
  error: string | null;
}

// ─── Plan Types ───────────────────────────────────────────────────────────────

export interface Plan {
  id: number;
  name: string;
  description?: string;
  price: number;
  currency: string;
  interval: 'month' | 'year';
  interval_count: number;
  features?: string;
  stripe_price_id?: string;
  stripe_product_id?: string;
  is_active: number;
  sort_order: number;
}

// ─── Transaction Types ────────────────────────────────────────────────────────

export type TransactionStatus = 'succeeded' | 'failed' | 'pending' | 'refunded';

export interface Transaction {
  id: number;
  user_id: number;
  subscription_id?: number;
  plan_id?: number;
  plan_name?: string;
  amount: number;
  currency: string;
  status: TransactionStatus;
  stripe_payment_intent_id?: string;
  stripe_invoice_id?: string;
  created_at: string;
}

export interface PaymentState {
  transactions: Transaction[];
  isLoading: boolean;
  error: string | null;
}

// ─── API Response Types ───────────────────────────────────────────────────────

export interface ApiResponse<T = unknown> {
  success: boolean;
  code: number;
  message: string;
  data: T;
}

export interface ApiError {
  success: false;
  code: number;
  message: string;
  data: null;
}

// ─── UI Types ─────────────────────────────────────────────────────────────────

export interface UIState {
  isLoading: boolean;
  loadingText?: string;
}

export type Theme = 'light' | 'dark';

export interface ThemeState {
  theme: Theme;
}

// ─── Stripe Types ─────────────────────────────────────────────────────────────

export interface CheckoutSessionPayload {
  plan_id: string;
  success_url?: string;
  cancel_url?: string;
}

export interface CheckoutSessionResponse {
  session_id: string;
  url: string;
}
