export type AdminRole = 'support' | 'admin' | 'super_admin'

export type AdminUserRow = {
  user_id: string
  role: AdminRole
  is_active: boolean
  created_at: string
}

export type AdminSubscriptionRequestRow = {
  id: number
  created_at: string
  status: 'pending' | 'approved' | 'rejected' | 'cancelled'
  method: 'wave' | 'orange_money' | 'card' | 'manual'
  amount_fcfa: number
  payer_phone: string | null
  note: string | null
  proof_url: string | null
  shop_id: string
  shop_name: string
  shop_phone: string | null
  user_id: string
  decided_at: string | null
  decided_by: string | null
}

export type AdminShopRow = {
  shop_id: string
  shop_name: string
  shop_phone: string
  plan: string | null
  is_active: boolean | null
  expires_at: string | null
  price_fcfa: number | null
  wave_number: string | null
  orange_money_number: string | null
  support_phone: string | null
  support_whatsapp: string | null
  entitlement_updated_at: string | null
}

export type EffectiveEntitlementRow = {
  shop_id: string
  plan: string
  is_active: boolean
  max_customers: number
  max_debts: number
  expires_at: string | null
  updated_at: string
  is_effective_active: boolean
  days_left: number | null
  has_pending_request: boolean
  status_effective: 'trial' | 'active' | 'pending' | 'expired'
}

export type MembershipRow = {
  shop_id: string
  user_id: string
  role: 'owner' | 'member'
  created_at: string
}

export type ProfileRow = {
  id: string
  full_name: string
  phone: string
  created_at: string
}

export type BillingSettingsRow = {
  shop_id: string
  price_fcfa: number
  wave_number: string
  orange_money_number: string
  support_phone: string
  support_whatsapp: string
  updated_at: string
}


export type RuntimeSettingsRow = {
  key: string
  app_name: string
  business_name: string
  website_url: string
  support_email: string
  support_phone: string
  support_whatsapp: string
  wave_number: string
  orange_money_number: string
  subscription_price_fcfa: number
  payment_instructions: string
  updated_at: string
}

export type AdminActionLogRow = {
  id: number
  admin_user_id: string
  action: string
  target_type: string
  target_id: string
  metadata: Record<string, unknown>
  created_at: string
}

export type DashboardSummary = {
  pendingRequests: number
  approvedRequests: number
  activeShops: number
  inactiveOrExpiredShops: number
}

export type ShopDetailPayload = {
  shop: AdminShopRow | null
  effectiveEntitlement: EffectiveEntitlementRow | null
  billingSettings: BillingSettingsRow | null
  memberships: Array<MembershipRow & { profile: ProfileRow | null }>
  recentRequests: Array<AdminSubscriptionRequestRow & { requesterProfile: ProfileRow | null; decidedByProfile: ProfileRow | null }>
}
