from __future__ import annotations
from typing import Dict, Any
import dataclasses
from .account_summary_guaranteed_stop_loss_order_mode import (
    AccountSummaryGuaranteedStopLossOrderMode,
)
from .account_summary_guaranteed_stop_loss_order_mode import (
    check_account_summary_guaranteed_stop_loss_order_mode,
)
from typing import Optional, Type, TypeVar

T = TypeVar("T", bound="AccountSummary")


@dataclasses.dataclass
class AccountSummary:
    """A summary representation of a client's Account. The AccountSummary does not provide to full specification of pending
    Orders, open Trades and Positions.

        Attributes:
            id (Optional[str]): The Account's identifier
            alias (Optional[str]): Client-assigned alias for the Account. Only provided if the Account has an alias set
            currency (Optional[str]): The home currency of the Account
            balance (Optional[str]): The current balance of the Account.
            created_by_user_id (Optional[int]): ID of the user that created the Account.
            created_time (Optional[str]): The date/time when the Account was created.
            guaranteed_stop_loss_order_mode (Optional[AccountSummaryGuaranteedStopLossOrderMode]): The current
                guaranteed Stop Loss Order mode of the Account.
            pl (Optional[str]): The total profit/loss realized over the lifetime of the Account.
            resettable_pl (Optional[str]): The total realized profit/loss for the Account since it was last reset by the
                client.
            resettable_pl_time (Optional[str]): The date/time that the Account's resettablePL was last reset.
            financing (Optional[str]): The total amount of financing paid/collected over the lifetime of the Account.
            commission (Optional[str]): The total amount of commission paid over the lifetime of the Account.
            guaranteed_execution_fees (Optional[str]): The total amount of fees charged over the lifetime of the Account
                for the execution of guaranteed Stop Loss Orders.
            margin_rate (Optional[str]): Client-provided margin rate override for the Account. The effective margin rate
                of the Account is the lesser of this value and the OANDA margin rate for the Account's division. This value is
                only provided if a margin rate override exists for the Account.
            margin_call_enter_time (Optional[str]): The date/time when the Account entered a margin call state. Only
                provided if the Account is in a margin call.
            margin_call_extension_count (Optional[int]): The number of times that the Account's current margin call was
                extended.
            last_margin_call_extension_time (Optional[str]): The date/time of the Account's last margin call extension.
            open_trade_count (Optional[int]): The number of Trades currently open in the Account.
            open_position_count (Optional[int]): The number of Positions currently open in the Account.
            pending_order_count (Optional[int]): The number of Orders currently pending in the Account.
            hedging_enabled (Optional[bool]): Flag indicating that the Account has hedging enabled.
            last_order_fill_timestamp (Optional[str]): The date/time of the last order that was filled for this account.
            unrealized_pl (Optional[str]): The total unrealized profit/loss for all Trades currently open in the
                Account.
            nav (Optional[str]): The net asset value of the Account. Equal to Account balance + unrealizedPL.
            margin_used (Optional[str]): Margin currently used for the Account.
            margin_available (Optional[str]): Margin available for Account currency.
            position_value (Optional[str]): The value of the Account's open positions represented in the Account's home
                currency.
            margin_closeout_unrealized_pl (Optional[str]): The Account's margin closeout unrealized PL.
            margin_closeout_nav (Optional[str]): The Account's margin closeout NAV.
            margin_closeout_margin_used (Optional[str]): The Account's margin closeout margin used.
            margin_closeout_percent (Optional[str]): The Account's margin closeout percentage. When this value is 1.0 or
                above the Account is in a margin closeout situation.
            margin_closeout_position_value (Optional[str]): The value of the Account's open positions as used for margin
                closeout calculations represented in the Account's home currency.
            withdrawal_limit (Optional[str]): The current WithdrawalLimit for the account which will be zero or a
                positive value indicating how much can be withdrawn from the account.
            margin_call_margin_used (Optional[str]): The Account's margin call margin used.
            margin_call_percent (Optional[str]): The Account's margin call percentage. When this value is 1.0 or above
                the Account is in a margin call situation.
            last_transaction_id (Optional[str]): The ID of the last Transaction created for the Account."""

    id: Optional[str]
    alias: Optional[str]
    currency: Optional[str]
    balance: Optional[str]
    created_by_user_id: Optional[int]
    created_time: Optional[str]
    guaranteed_stop_loss_order_mode: Optional[AccountSummaryGuaranteedStopLossOrderMode]
    pl: Optional[str]
    resettable_pl: Optional[str]
    resettable_pl_time: Optional[str]
    financing: Optional[str]
    commission: Optional[str]
    guaranteed_execution_fees: Optional[str]
    margin_rate: Optional[str]
    margin_call_enter_time: Optional[str]
    margin_call_extension_count: Optional[int]
    last_margin_call_extension_time: Optional[str]
    open_trade_count: Optional[int]
    open_position_count: Optional[int]
    pending_order_count: Optional[int]
    hedging_enabled: Optional[bool]
    last_order_fill_timestamp: Optional[str]
    unrealized_pl: Optional[str]
    nav: Optional[str]
    margin_used: Optional[str]
    margin_available: Optional[str]
    position_value: Optional[str]
    margin_closeout_unrealized_pl: Optional[str]
    margin_closeout_nav: Optional[str]
    margin_closeout_margin_used: Optional[str]
    margin_closeout_percent: Optional[str]
    margin_closeout_position_value: Optional[str]
    withdrawal_limit: Optional[str]
    margin_call_margin_used: Optional[str]
    margin_call_percent: Optional[str]
    last_transaction_id: Optional[str]

    @classmethod
    def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
        d = src_dict.copy()
        id = d.pop("id", None)
        alias = d.pop("alias", None)
        currency = d.pop("currency", None)
        balance = d.pop("balance", None)
        created_by_user_id = d.pop("createdByUserID", None)
        created_time = d.pop("createdTime", None)
        _guaranteed_stop_loss_order_mode = d.pop("guaranteedStopLossOrderMode", None)
        guaranteed_stop_loss_order_mode: Optional[
            AccountSummaryGuaranteedStopLossOrderMode
        ]
        if _guaranteed_stop_loss_order_mode is None:
            guaranteed_stop_loss_order_mode = None
        else:
            guaranteed_stop_loss_order_mode = (
                check_account_summary_guaranteed_stop_loss_order_mode(
                    _guaranteed_stop_loss_order_mode
                )
            )
        pl = d.pop("pl", None)
        resettable_pl = d.pop("resettablePL", None)
        resettable_pl_time = d.pop("resettablePLTime", None)
        financing = d.pop("financing", None)
        commission = d.pop("commission", None)
        guaranteed_execution_fees = d.pop("guaranteedExecutionFees", None)
        margin_rate = d.pop("marginRate", None)
        margin_call_enter_time = d.pop("marginCallEnterTime", None)
        margin_call_extension_count = d.pop("marginCallExtensionCount", None)
        last_margin_call_extension_time = d.pop("lastMarginCallExtensionTime", None)
        open_trade_count = d.pop("openTradeCount", None)
        open_position_count = d.pop("openPositionCount", None)
        pending_order_count = d.pop("pendingOrderCount", None)
        hedging_enabled = d.pop("hedgingEnabled", None)
        last_order_fill_timestamp = d.pop("lastOrderFillTimestamp", None)
        unrealized_pl = d.pop("unrealizedPL", None)
        nav = d.pop("NAV", None)
        margin_used = d.pop("marginUsed", None)
        margin_available = d.pop("marginAvailable", None)
        position_value = d.pop("positionValue", None)
        margin_closeout_unrealized_pl = d.pop("marginCloseoutUnrealizedPL", None)
        margin_closeout_nav = d.pop("marginCloseoutNAV", None)
        margin_closeout_margin_used = d.pop("marginCloseoutMarginUsed", None)
        margin_closeout_percent = d.pop("marginCloseoutPercent", None)
        margin_closeout_position_value = d.pop("marginCloseoutPositionValue", None)
        withdrawal_limit = d.pop("withdrawalLimit", None)
        margin_call_margin_used = d.pop("marginCallMarginUsed", None)
        margin_call_percent = d.pop("marginCallPercent", None)
        last_transaction_id = d.pop("lastTransactionID", None)
        account_summary = cls(
            id=id,
            alias=alias,
            currency=currency,
            balance=balance,
            created_by_user_id=created_by_user_id,
            created_time=created_time,
            guaranteed_stop_loss_order_mode=guaranteed_stop_loss_order_mode,
            pl=pl,
            resettable_pl=resettable_pl,
            resettable_pl_time=resettable_pl_time,
            financing=financing,
            commission=commission,
            guaranteed_execution_fees=guaranteed_execution_fees,
            margin_rate=margin_rate,
            margin_call_enter_time=margin_call_enter_time,
            margin_call_extension_count=margin_call_extension_count,
            last_margin_call_extension_time=last_margin_call_extension_time,
            open_trade_count=open_trade_count,
            open_position_count=open_position_count,
            pending_order_count=pending_order_count,
            hedging_enabled=hedging_enabled,
            last_order_fill_timestamp=last_order_fill_timestamp,
            unrealized_pl=unrealized_pl,
            nav=nav,
            margin_used=margin_used,
            margin_available=margin_available,
            position_value=position_value,
            margin_closeout_unrealized_pl=margin_closeout_unrealized_pl,
            margin_closeout_nav=margin_closeout_nav,
            margin_closeout_margin_used=margin_closeout_margin_used,
            margin_closeout_percent=margin_closeout_percent,
            margin_closeout_position_value=margin_closeout_position_value,
            withdrawal_limit=withdrawal_limit,
            margin_call_margin_used=margin_call_margin_used,
            margin_call_percent=margin_call_percent,
            last_transaction_id=last_transaction_id,
        )
        account_summary.additional_properties = d
        return account_summary

    def to_dict(self) -> Dict[str, Any]:
        """Convert the dataclass instance to a dictionary."""
        return dataclasses.asdict(self)
