"""Synor Wallet SDK Types."""

from dataclasses import dataclass, field
from enum import Enum
from typing import Optional


class Network(str, Enum):
    """Network type."""
    MAINNET = "mainnet"
    TESTNET = "testnet"


class WalletType(str, Enum):
    """Wallet type."""
    STANDARD = "standard"
    MULTISIG = "multisig"
    STEALTH = "stealth"
    HARDWARE = "hardware"


class Priority(str, Enum):
    """Transaction priority."""
    LOW = "low"
    MEDIUM = "medium"
    HIGH = "high"
    URGENT = "urgent"


@dataclass
class WalletConfig:
    """Wallet SDK configuration."""
    api_key: str
    endpoint: str = "https://wallet.synor.cc/api/v1"
    network: Network = Network.MAINNET
    timeout: float = 30.0
    debug: bool = False
    derivation_path: Optional[str] = None


@dataclass
class Wallet:
    """Wallet instance."""
    id: str
    address: str
    public_key: str
    type: WalletType
    created_at: int


@dataclass
class CreateWalletResult:
    """Wallet creation result."""
    wallet: Wallet
    mnemonic: str


@dataclass
class StealthAddress:
    """Stealth address for private payments."""
    address: str
    view_key: str
    spend_key: str
    ephemeral_key: Optional[str] = None


@dataclass
class TransactionInput:
    """Transaction input."""
    txid: str
    vout: int
    amount: str
    script_sig: Optional[str] = None


@dataclass
class TransactionOutput:
    """Transaction output."""
    address: str
    amount: str
    script_pub_key: Optional[str] = None


@dataclass
class Transaction:
    """Unsigned transaction."""
    version: int
    inputs: list[TransactionInput]
    outputs: list[TransactionOutput]
    lock_time: int = 0
    fee: Optional[str] = None


@dataclass
class SignedTransaction:
    """Signed transaction."""
    raw: str
    txid: str
    size: int
    weight: Optional[int] = None


@dataclass
class SignedMessage:
    """Signed message."""
    signature: str
    public_key: str
    address: str


@dataclass
class UTXO:
    """Unspent Transaction Output."""
    txid: str
    vout: int
    amount: str
    address: str
    confirmations: int
    script_pub_key: Optional[str] = None


@dataclass
class Balance:
    """Balance information."""
    confirmed: str
    unconfirmed: str
    total: str


@dataclass
class TokenBalance:
    """Token balance."""
    token: str
    symbol: str
    decimals: int
    balance: str


@dataclass
class BalanceResponse:
    """Full balance response."""
    native: Balance
    tokens: list[TokenBalance] = field(default_factory=list)


@dataclass
class FeeEstimate:
    """Fee estimation result."""
    priority: Priority
    fee_rate: str
    estimated_blocks: int


@dataclass
class GetUtxosOptions:
    """UTXO query options."""
    min_confirmations: int = 1
    min_amount: Optional[str] = None


@dataclass
class ImportWalletOptions:
    """Import wallet options."""
    mnemonic: str
    passphrase: Optional[str] = None
    type: WalletType = WalletType.STANDARD


@dataclass
class BuildTransactionOptions:
    """Transaction building options."""
    to: str
    amount: str
    fee_rate: Optional[float] = None
    utxos: Optional[list[UTXO]] = None
    change_address: Optional[str] = None
