"""Type definitions for Route402 SDK"""

from enum import Enum
from dataclasses import dataclass
from typing import Optional
from datetime import datetime


class PaymentStatus(str, Enum):
    """Payment status enum"""
    PENDING = "PENDING"
    BROADCASTED = "BROADCASTED"
    MINED = "MINED"
    CONFIRMED = "CONFIRMED"
    FAILED = "FAILED"


class Chain(int, Enum):
    """Supported blockchain networks"""
    BASE = 8453
    POLYGON_AMOY = 80002  # Testnet


@dataclass
class Payment:
    """Payment object"""
    id: str
    chain_id: int
    buyer: str
    seller: str
    amount: str
    fee_bps: int
    tx_hash: Optional[str]
    status: PaymentStatus
    reference: Optional[str]
    created_at: datetime
    confirmed_at: Optional[datetime] = None

    @property
    def fee_amount(self) -> float:
        """Calculate fee amount in USDC"""
        return float(self.amount) * self.fee_bps / 10000

    @property
    def net_amount(self) -> float:
        """Calculate net amount (amount - fee) in USDC"""
        return float(self.amount) - self.fee_amount

    @property
    def is_confirmed(self) -> bool:
        """Check if payment is confirmed"""
        return self.status == PaymentStatus.CONFIRMED

    @property
    def is_pending(self) -> bool:
        """Check if payment is pending"""
        return self.status in [PaymentStatus.PENDING, PaymentStatus.BROADCASTED, PaymentStatus.MINED]


@dataclass
class TransactionData:
    """Transaction data for signing"""
    to: str
    data: str
    value: str
    chain_id: int
    gas_limit: Optional[int] = None
