/**
 * Synor Economics SDK Types
 * Pricing, billing, staking, and discount management.
 */

// Service types for pricing
export type ServiceType =
  | 'compute'
  | 'storage'
  | 'database'
  | 'hosting'
  | 'bridge'
  | 'rpc';

// Billing period
export type BillingPeriod = 'hourly' | 'daily' | 'weekly' | 'monthly';

// Stake status
export type StakeStatus = 'active' | 'unstaking' | 'withdrawn' | 'slashed';

// Discount type
export type DiscountType = 'percentage' | 'fixed' | 'volume' | 'referral';

// Invoice status
export type InvoiceStatus = 'pending' | 'paid' | 'overdue' | 'cancelled';

// Usage metrics for pricing
export interface UsageMetrics {
  computeHours?: number;
  storageBytes?: number;
  databaseOps?: number;
  hostingRequests?: number;
  bridgeTransfers?: number;
  rpcCalls?: number;
}

// Usage plan for cost estimation
export interface UsagePlan {
  services: ServiceUsage[];
  period: BillingPeriod;
  startDate?: number;
  endDate?: number;
}

// Service usage in plan
export interface ServiceUsage {
  service: ServiceType;
  metrics: UsageMetrics;
  tier?: string;
}

// Price breakdown
export interface Price {
  service: ServiceType;
  basePrice: string;
  quantity: string;
  unit: string;
  subtotal: string;
  discounts: AppliedDiscount[];
  total: string;
  currency: string;
}

// Cost estimate
export interface CostEstimate {
  services: Price[];
  subtotal: string;
  discounts: AppliedDiscount[];
  taxes: TaxAmount[];
  total: string;
  currency: string;
  validUntil: number;
}

// Tax amount
export interface TaxAmount {
  name: string;
  rate: number;
  amount: string;
}

// Applied discount
export interface AppliedDiscount {
  code: string;
  type: DiscountType;
  value: string;
  savings: string;
  description?: string;
}

// Usage record
export interface Usage {
  period: BillingPeriod;
  startDate: number;
  endDate: number;
  services: ServiceUsageRecord[];
  totalCost: string;
  currency: string;
}

// Service usage record
export interface ServiceUsageRecord {
  service: ServiceType;
  metrics: UsageMetrics;
  cost: string;
  details: UsageDetail[];
}

// Usage detail
export interface UsageDetail {
  timestamp: number;
  operation: string;
  quantity: number;
  unit: string;
  cost: string;
}

// Invoice
export interface Invoice {
  id: string;
  status: InvoiceStatus;
  period: BillingPeriod;
  startDate: number;
  endDate: number;
  items: InvoiceItem[];
  subtotal: string;
  discounts: AppliedDiscount[];
  taxes: TaxAmount[];
  total: string;
  currency: string;
  dueDate: number;
  paidAt?: number;
  paymentMethod?: string;
}

// Invoice item
export interface InvoiceItem {
  service: ServiceType;
  description: string;
  quantity: string;
  unitPrice: string;
  total: string;
}

// Account balance
export interface AccountBalance {
  available: string;
  pending: string;
  reserved: string;
  total: string;
  currency: string;
  creditLimit?: string;
  lastUpdated: number;
}

// Stake receipt
export interface StakeReceipt {
  id: string;
  amount: string;
  lockDuration: number;
  startDate: number;
  endDate: number;
  apy: string;
  estimatedRewards: string;
  txHash: string;
}

// Unstake receipt
export interface UnstakeReceipt {
  id: string;
  stakeId: string;
  amount: string;
  rewards: string;
  total: string;
  unbondingPeriod: number;
  availableAt: number;
  txHash: string;
}

// Stake info
export interface StakeInfo {
  id: string;
  amount: string;
  status: StakeStatus;
  lockDuration: number;
  startDate: number;
  endDate: number;
  apy: string;
  earnedRewards: string;
  pendingRewards: string;
  validator?: string;
}

// Staking rewards
export interface StakingRewards {
  totalEarned: string;
  pending: string;
  claimed: string;
  lastClaimDate?: number;
  nextClaimAvailable?: number;
  stakes: StakeRewardDetail[];
}

// Stake reward detail
export interface StakeRewardDetail {
  stakeId: string;
  earned: string;
  pending: string;
  apy: string;
}

// Discount
export interface Discount {
  code: string;
  type: DiscountType;
  value: string;
  description: string;
  validFrom: number;
  validUntil: number;
  minPurchase?: string;
  maxDiscount?: string;
  applicableServices: ServiceType[];
  usageLimit?: number;
  usedCount: number;
}

// Staking options
export interface StakeOptions {
  validator?: string;
  autoCompound?: boolean;
  lockDuration?: number;
}

// Economics config
export interface EconomicsConfig {
  apiKey: string;
  endpoint?: string;
  timeout?: number;
  retries?: number;
  debug?: boolean;
}

// Internal response types
export interface PriceResponse {
  price: Price;
}

export interface InvoicesResponse {
  invoices: Invoice[];
}

export interface StakesResponse {
  stakes: StakeInfo[];
}

export interface DiscountsResponse {
  discounts: Discount[];
}
