
import os
import sys
import pandas as pd
from dotenv import load_dotenv

# Add src to path
sys.path.append(os.path.join(os.path.dirname(__file__), '../src'))

from fetchers.jp_fetcher import JpFetcher

def test_jp_fetcher():
    load_dotenv()
    token = os.getenv("IFIND_REFRESH_TOKEN")
    if not token:
        print("Missing IFIND_REFRESH_TOKEN in .env")
        return

    fetcher = JpFetcher(token)
    symbol = "7203" # Toyota
    
    print(f"--- Fetching Market Metrics for {symbol} ---")
    metrics = fetcher.get_market_metrics(symbol)
    print(metrics)
    
    print(f"\n--- Fetching Income Statement for {symbol} ---")
    df_is = fetcher.get_income_statement(symbol)
    if not df_is.empty:
        print(df_is.head())
    else:
        print("Income Statement is empty!")

    print(f"\n--- Fetching Balance Sheet for {symbol} ---")
    df_bs = fetcher.get_balance_sheet(symbol)
    if not df_bs.empty:
        print(df_bs.head())
    else:
        print("Balance Sheet is empty!")

    print(f"\n--- Fetching Cash Flow for {symbol} ---")
    df_cf = fetcher.get_cash_flow(symbol)
    if not df_cf.empty:
        print(df_cf.head())
    else:
        print("Cash Flow is empty!")

    print(f"\n--- Fetching Historical Metrics for {symbol} ---")
    dates = ["2023-12-21", "2024-06-30"]
    df_hist = fetcher.get_historical_metrics(symbol, dates)
    if not df_hist.empty:
        print(df_hist)
    else:
        print("Historical Metrics is empty!")

    print(f"\n--- Fetching Dividends for {symbol} ---")
    df_div = fetcher.get_dividends(symbol)
    if not df_div.empty:
        print(df_div.head())
    else:
        print("Dividends empty or not found.")

if __name__ == "__main__":
    test_jp_fetcher()
