export interface User {
  id: number
  name: string
  email: string
  phone: string | null
  company: string | null
  admin_notes?: string | null
  status: string
  two_factor_enabled?: boolean
}

export interface UserProfile {
  billing_address_line1: string | null
  billing_address_line2: string | null
  billing_city: string | null
  billing_state: string | null
  billing_zip: string | null
  billing_country: string | null
  tax_id: string | null
  tax_exempt: boolean
  company_name: string | null
  company_vat: string | null
}

export interface AuthProps {
  user: User | null
}

export interface DomainProps {
  marketing: string
  account: string
  admin: string
}

export interface FlashProps {
  success?: string
  error?: string
  info?: string
  new_password?: string
}

export interface SharedPageProps {
  auth: AuthProps
  flash: FlashProps
  domains: DomainProps
}

export interface Plan {
  id: number
  name: string
  slug: string
  description: string | null
  price: string
  billing_cycle: string
  service_type: string
  features: Record<string, string> | null
  stock_quantity: number | null
  status: string
  sort_order: number
}

export interface Subscription {
  id: number
  type: string
  stripe_status: string
  gateway: string
  current_period_start: string | null
  current_period_end: string | null
  ends_at: string | null
  created_at: string
  plan?: Plan
}

export interface PaymentMethod {
  id: string
  brand: string
  last_four: string
  exp_month: number
  exp_year: number
  is_default: boolean
}

export interface Invoice {
  id: number
  number: string
  status: string
  total: string
  tax: string
  currency: string
  gateway: string | null
  gateway_invoice_id: string | null
  invoice_pdf: string | null
  notes: string | null
  due_date: string | null
  paid_at: string | null
  created_at: string
  updated_at: string
  user?: {
    id: number
    name: string
    email: string
    status?: string
  }
  items?: InvoiceLineItem[]
}

export interface InvoiceLineItem {
  id: number
  invoice_id: number
  description: string
  amount: string
  quantity: number
  created_at: string
  updated_at: string
}

export interface Transaction {
  id: number
  gateway: string
  payment_method: string
  status: string
  description: string
  amount: string
  created_at: string
}

export interface PaginatedResponse<T> {
  data: T[]
  links: PaginationLink[]
  from: number
  to: number
  total: number
  last_page: number
}

export interface PaginationLink {
  url: string | null
  label: string
  active: boolean
}

export interface Service {
  id: number
  user_id: number
  subscription_id: number | null
  plan_id: number
  service_type: string
  platform: string
  platform_service_id: string | null
  status: 'pending' | 'active' | 'suspended' | 'terminated'
  ipv4_address: string | null
  ipv6_address: string | null
  hostname: string | null
  domain: string | null
  auto_renew: boolean
  provisioning_info: Record<string, unknown> | null
  provisioned_at: string | null
  suspended_at: string | null
  terminated_at: string | null
  created_at: string
  updated_at: string
  plan?: Plan
  subscription?: Subscription
}

export interface Coupon {
  id: number
  code: string
  type: 'percentage' | 'fixed'
  value: string
  currency: string | null
  applies_to: number[] | null
  max_uses: number | null
  times_used: number
  active: boolean
  expires_at: string | null
  created_at: string
  redemptions_count?: number
}

export interface CouponWithStats extends Coupon {
  redemptions_count: number
  redemptions_sum_discount_amount: string | null
  redemptions_max_created_at: string | null
}

export interface CouponRedemption {
  id: number
  coupon_id: number
  user_id: number
  subscription_id: number | null
  discount_amount: string
  created_at: string
  user?: {
    id: number
    name: string
    email: string
  }
  subscription?: {
    id: number
    type: string
    stripe_status: string
  }
}

export interface CouponRedemptionStats {
  total_redemptions: number
  total_discount: number
  latest_redemption: string | null
}

export interface SupportTicket {
  id: number
  user_id: number
  ticket_reference: string | null
  customer_email: string | null
  subject: string
  status: 'open' | 'in_progress' | 'waiting' | 'closed'
  priority: 'low' | 'medium' | 'high' | 'urgent'
  department: 'billing' | 'technical' | 'sales' | 'general'
  last_reply_at: string | null
  created_at: string
  updated_at: string
  user?: {
    id: number
    name: string
    email: string
    status?: string
    company?: string | null
  }
  replies?: TicketReply[]
}

export interface TicketReply {
  id: number
  ticket_id: number
  user_id: number
  body: string
  is_staff_reply: boolean
  message_id: string | null
  from_email: string | null
  via_email: boolean
  created_at: string
  updated_at: string
  user?: {
    id: number
    name: string
    email: string
  }
}

export interface AuditLog {
  id: number
  user_id: number | null
  admin_id: number | null
  action: string
  resource_type: string | null
  resource_id: number | null
  ip_address: string | null
  user_agent: string | null
  changes: Record<string, unknown> | null
  created_at: string
  user?: {
    id: number
    name: string
    email: string
  }
  admin?: {
    id: number
    name: string
    email: string
  }
}

export interface UpcomingRenewal {
  id: number
  plan_name: string
  plan_price: string | null
  billing_cycle: string | null
  renewal_date: string
  status: string
  auto_renew: boolean
  service_id: number | null
  days_until_renewal: number
}

export interface TaxRate {
  id: number
  name: string
  country_code: string
  region_code: string | null
  rate: string
  type: 'inclusive' | 'exclusive'
  priority: number
  is_active: boolean
  created_at: string
  updated_at: string
}

export type StatusColor = 'success' | 'error' | 'warning' | 'info' | 'secondary'
