
    N j                     t    S SK JrJr  S SKrS SKJrJrJr  SSK	J
r
  SSKJr  SSKJr  \
 S3r " S	 S
\5      rg)    )ABCabstractmethodN)DictListOptional   )_QUERY1_URL_)YfData)Tickerz/v1/financec                   h   \ rS rSrSrSS\4S jjr\S\4S j5       r\S\4S j5       r	\S\4S	 j5       r
\S\4S
 j5       r\S\4S j5       r\S\\R"                     4S j5       r\S\\\\4      4S j5       rS\4S jrSS jrS\4S jrS\\R"                     4S jr\SS j5       rSS jrSrg)Domain   z
Abstract base class representing a domain entity in financial data, with key attributes 
and methods for fetching and parsing data. Derived classes must implement the `_fetch_and_parse()` method.
Nkeyc                 ~    Xl         X l        [        US9U l        SU l        SU l        SU l        SU l        SU l        g)z
Initializes the Domain object with a key, session.

Args:
    key (str): Unique key identifying the domain entity.
    session (Optional[requests.Session]): Session object for HTTP requests. Defaults to None.
)sessionN)	_keyr   r
   _data_name_symbol	_overview_top_companies_research_reports)selfr   r   s      g/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/yfinance/domain/domain.py__init__Domain.__init__   s?     	#G4
$(
&*)-7;AE    returnc                     U R                   $ )za
Retrieves the key of the domain entity.

Returns:
    str: The unique key of the domain entity.
)r   r   s    r   r   
Domain.key#   s     yyr   c                 P    U R                  U R                  5        U R                  $ )z\
Retrieves the name of the domain entity.

Returns:
    str: The name of the domain entity.
)_ensure_fetchedr   r    s    r   nameDomain.name-   s      	TZZ(zzr   c                 P    U R                  U R                  5        U R                  $ )zj
Retrieves the symbol of the domain entity.

Returns:
    str: The symbol representing the domain entity.
)r#   r   r    s    r   symbolDomain.symbol8   s      	T\\*||r   c                 b    U R                  U R                  5        [        U R                  5      $ )z
Retrieves a Ticker object based on the domain entity's symbol.

Returns:
    Ticker: A Ticker object associated with the domain entity.
)r#   r   r   r    s    r   tickerDomain.tickerC   s%     	T\\*dll##r   c                 P    U R                  U R                  5        U R                  $ )z
Retrieves the overview information of the domain entity.

Returns:
    Dict: A dictionary containing an overview of the domain entity.
)r#   r   r    s    r   overviewDomain.overviewN   s      	T^^,~~r   c                 P    U R                  U R                  5        U R                  $ )z
Retrieves the top companies within the domain entity.

Returns:
    pandas.DataFrame: A DataFrame containing the top companies in the domain.
)r#   r   r    s    r   top_companiesDomain.top_companiesY   s$     	T001"""r   c                 P    U R                  U R                  5        U R                  $ )z
Retrieves research reports related to the domain entity.

Returns:
    List[Dict[str, str]]: A list of research reports, where each report is a dictionary with metadata.
)r#   r   r    s    r   research_reportsDomain.research_reportsd   s$     	T334%%%r   c                 F    SSSSS.nU R                   R                  XS9nU$ )z
Fetches data from the given query URL.

Args:
    query_url (str): The URL used for the data query.

Returns:
    Dict: The JSON response data from the request.
truezen-USUS)	formattedwithReturnslangregion)params)r   get_raw_json)r   	query_urlparams_dictresults       r   _fetchDomain._fetcho   s/     %+67^bc(((Gr   c                     UR                  S5      U l        UR                  S5      U l        U R                  UR                  S0 5      5      U l        U R                  UR                  S0 5      5      U l        UR                  S5      U l        g)z
Parses and assigns common data fields such as name, symbol, overview, and top companies.

Args:
    data (Dict): The raw data received from the API.
r$   r'   r-   topCompaniesresearchReportsN)getr   r   _parse_overviewr   _parse_top_companiesr   r   )r   datas     r   _parse_and_assign_commonDomain._parse_and_assign_common}   sr     XXf%
xx)--dhhz2.FG"77QS8TU!%*;!<r   c           
      V   UR                  SS5      UR                  S0 5      R                  SS5      UR                  SS5      UR                  SS5      UR                  SS5      UR                  S0 5      R                  SS5      UR                  S	0 5      R                  SS5      S
.$ )z
Parses the overview data for the domain entity.

Args:
    overview (Dict): The raw overview data.

Returns:
    Dict: A dictionary containing parsed overview information.
companiesCountN	marketCaprawmessageBoardIddescriptionindustriesCountmarketWeightemployeeCount)companies_count
market_capmessage_board_idrQ   industries_countmarket_weightemployee_count)rF   )r   r-   s     r   rG   Domain._parse_overview   s      (||,<dC",,{B7;;E4H (-=t D#<<t< (-> E%\\."=AA%N&ll?B?CCE4P
 	
r   c           
      0   / SQnU Vs/ s HV  nUR                  S5      UR                  S5      UR                  S5      UR                  S0 5      R                  SS5      4PMX     nnU(       d  g[        R                  " XBS9R                  S5      $ s  snf )	z
Parses the top companies data and converts it into a pandas DataFrame.

Args:
    top_companies (Dict): The raw top companies data.

Returns:
    Optional[pandas.DataFrame]: A DataFrame containing top company data, or None if no data is available.
)r'   r$   ratingzmarket weightr'   r$   r]   rS   rO   N)columns)rF   _pd	DataFrame	set_index)r   r0   top_companies_columnctop_companies_valuess        r   rH   Domain._parse_top_companies   s      M Ta b Taa "#x !f !h !nR 8 < <U4 H!J Ta 	  b
 $}}1PZZ[cdd bs   ABc                     [        S5      e)zi
Abstract method for fetching and parsing domain-specific data. 
Must be implemented by derived classes.
z>_fetch_and_parse() needs to be implemented by children classes)NotImplementedErrorr    s    r   _fetch_and_parseDomain._fetch_and_parse   s     ""bccr   c                 ,    Uc  U R                  5         gg)z
Ensures that the given attribute is fetched by calling `_fetch_and_parse()` if the attribute is None.

Args:
    attribute: The attribute to check and potentially fetch.
N)rh   )r   	attributes     r   r#   Domain._ensure_fetched   s     !!# r   )r   r   r   r   r   r   r   r   )N)r   N)__name__
__module____qualname____firstlineno____doc__strr   propertyr   r$   r'   r   r*   r   r-   r   r_   r`   r0   r   r3   rA   rJ   rG   rH   r   rh   r#   __static_attributes__ r   r   r   r      s7   
FC F$ S   c      $ $ $ $   #x6 # # &$tCH~"6 & &4 =
4 
(eXcmm5L e* d d$r   r   )abcr   r   pandasr_   typingr   r   r   constr	   rI   r
   r*   r   _QUERY_URL_r   ru   r   r   <module>r{      s4    #  ' '    k*x$S x$r   