"This is the class that will determine the WACC for a company"

import sys

sys.path.append(r".")

import os

import numpy as np
import pandas as pd
import requests
from dotenv import load_dotenv

from models.company_financials import CompanyFinancials

load_dotenv()


class WACC:
    "This class will determine the WACC for a company"

    headers = {
        "Content-Type": "application/json",
        "Accept": "application/json",
    }

    def __init__(self, WACC: float):
        self.WACC = WACC

        # return self.WACC

    def calculate_wacc(self):
        "This method will calculate the WACC for a company"
        return self.WACC

    # def __init__(self, company: CompanyFinancials, beta_comps: list[str], debt_comps: list[str], ideal_cap_structure: dict[str: float]) -> None:
    #     """
    #     This is the constructor for the WACC class
    #     input:
    #         company: CompanyFinancials
    #         beta_comps: list of tickers
    #         debt_comps: list of tickers
    #         ideal_cap_structure: dictionary
    #     """

    #     self.company = company
    #     self.beta_comps = beta_comps
    #     self.debt_comps = debt_comps

    #     # get the ideal capital structure
    #     self.ideal_cap_structure = self.ideal_capital_structure() if ideal_cap_structure is None else ideal_cap_structure

    #     # get risk free rate
    #     self.rf_rate, self.rf_date_as_of = self.risk_free_rate()

    def ideal_capital_structure(self):
        "This method will determine the ideal capital structure for a company"

        pass

    def cost_of_debt(self):
        "This method will determine the cost of debt for a company"
        pass

    def cost_of_equity(self):
        "This method will determine the cost of equity for a company"
        pass

    def beta(self):
        "This method will determine the beta for a company"
        pass

    def equity_risk_premium(self):
        "This method will determine the equity risk premium for a company"
        excel_url = "https://www.stern.nyu.edu/~adamodar/pc/datasets/histimpl.xls"
        df_ERP = pd.read_excel(excel_url, skiprows=6)
        df_ERP = df_ERP.dropna(subset=["Year"]).iloc[:-1, :].set_index("Year")
        self.ERP = df_ERP["Implied ERP (FCFE)"].values[-1]
        pass

    def risk_free_rate(self):
        "This method will determine the risk free rate for a company"
        # using the alphavantage API
        _interval = "daily"
        _maturity = "10year"
        url = f"https://www.alphavantage.co/query?function=TREASURY_YIELD&interval={_interval}&maturity={_maturity}&apikey={os.getenv('Alpha_Vantage')}"
        response = requests.get(url, headers=self.headers, timeout=5)
        data = response.json()
        risk_free_rate_value = data["data"][0]["value"]
        risk_free_rate_as_of = data["data"][0]["date"]
        return risk_free_rate_value, risk_free_rate_as_of

    def market_return(self):
        "This method will determine the market return for a company"
        pass

    def tax_rate(self, company_ticker: str):
        "This method will determine the tax rate for a company"
        pass

    def size_mutliple(self, company_ticker: str):
        "This method will determine the size multiple for a company"
        #
        pass

    def wacc(self):
        "This method will determine the WACC for a company"
        pass


if __name__ == "__main__":
    w = WACC(0.05)

    print(w.calculate_wacc())
