from typing import List, Optional, Union

from matplotlib import pyplot as plt

from .asset_list import AssetList
from .common.helpers.helpers import Float
from .settings import default_ticker


class Plots(AssetList):
    """
    Plotting tools collection to use with financial charts (Efficient Frontier, Assets and Transition map etc.)

    Parameters
    ----------
    assets : list, default None
        List of assets. Could include tickers or asset like objects (Asset, Portfolio).
        If None a single asset list with a default ticker is used.

    first_date : str, default None
        First date of monthly return time series.
        If None the first date is calculated automatically as the oldest available date for the listed assets.

    last_date : str, default None
        Last date of monthly return time series.
        If None the last date is calculated automatically as the newest available date for the listed assets.

    ccy : str, default 'USD'
        Base currency for the list of assets. All risk metrics and returns are adjusted to the base currency.

    inflation : bool, default True
        Defines whether to take inflation data into account in the calculations.
        Including inflation could limit available data (last_date, first_date)
        as the inflation data is usually published with a one-month delay.
        With inflation = False some properties like real return are not available.
    """

    def __init__(
        self,
        assets: List[str] = [default_ticker],
        first_date: Optional[str] = None,
        last_date: Optional[str] = None,
        ccy: str = "USD",
        inflation: bool = True,
    ):
        super().__init__(
            assets,
            first_date=first_date,
            last_date=last_date,
            ccy=ccy,
            inflation=inflation,
        )
        self.ax = None

    def _verify_axes(self):
        if self.ax:
            del self.ax
        self.ax = plt.gca()
