import type { Address, Hex } from 'viem';

/**
 * Information request type for payment data callbacks
 */
export interface InfoRequest {
  /** The type of information being requested */
  type: 'email' | 'physicalAddress' | 'phoneNumber' | 'name' | 'onchainAddress' | string;
  /** Whether this information is optional */
  optional?: boolean;
}

/**
 * Information responses collected from info requests
 */
export interface PayerInfoResponses {
  /** User's email address */
  email?: string;
  /** User's physical address */
  physicalAddress?: {
    address1: string;
    address2?: string;
    city: string;
    state: string;
    postalCode: string;
    countryCode: string;
    name?: {
      firstName: string;
      familyName: string;
    };
  };
  /** User's phone number */
  phoneNumber?: {
    number: string;
    country: string;
  };
  /** User's name */
  name?: {
    firstName: string;
    familyName: string;
  };
  /** User's on-chain address */
  onchainAddress?: string;
}

/**
 * Payer information configuration for payment data callbacks
 */
export interface PayerInfo {
  /** Information requests from the payer */
  requests: InfoRequest[];
  /** Callback URL for sending the payer information */
  callbackURL: string;
}

/**
 * Options for making a payment
 */
export interface PaymentOptions {
  /** Amount of USDC to send as a string (e.g., "10.50") */
  amount: string;
  /** Ethereum address to send payment to */
  to: string;
  /** Whether to use testnet (Base Sepolia). Defaults to false (mainnet) */
  testnet?: boolean;
  /** Optional payer information configuration for data callbacks */
  payerInfo?: PayerInfo;
}

/**
 * Successful payment result
 */
export interface PaymentSuccess {
  success: true;
  /** Transaction ID (hash) of the payment */
  id: string;
  /** The amount that was sent */
  amount: string;
  /** The address that received the payment */
  to: Address;
  /** Optional responses from information requests */
  payerInfoResponses?: PayerInfoResponses;
}

/**
 * Failed payment result
 */
export interface PaymentError {
  success: false;
  /** Error message describing what went wrong */
  error: string;
  /** The amount that was attempted */
  amount: string;
  /** The address that would have received the payment */
  to: Address;
}

/**
 * Result of a payment transaction
 */
export type PaymentResult = PaymentSuccess | PaymentError;

/**
 * Options for checking payment status
 */
export interface PaymentStatusOptions {
  /** Transaction ID (userOp hash) to check status for */
  id: string;
  /** Whether to check on testnet (Base Sepolia). Defaults to false (mainnet) */
  testnet?: boolean;
}

/**
 * Possible payment status types
 */
export type PaymentStatusType = 'pending' | 'completed' | 'failed' | 'not_found';

/**
 * Payment status information
 */
export interface PaymentStatus {
  /** Current status of the payment */
  status: PaymentStatusType;
  /** Transaction ID that was checked */
  id: Hex;
  /** Human-readable message about the status */
  message: string;
  
  // Additional fields that may be present depending on status
  /** Sender address (present for pending, completed, and failed) */
  sender?: string;
  /** Amount sent (present for completed transactions, parsed from logs) */
  amount?: string;
  /** Recipient address (present for completed transactions, parsed from logs) */
  recipient?: string;
  /** Error message (present for failed status - includes both on-chain failure reasons and off-chain errors) */
  error?: string;
}

/**
 * Internal type for payment execution result
 */
