# coding: utf-8

"""
    FinancialReports API

     Welcome to the FinancialReports API.  ### Access Levels This API is tiered based on data granularity.  | Level | Name | Description | | :--- | :--- | :--- | | **Level 1** | **Standard Access** | Access to raw PDF/XBRL metadata, company profiles, ISIC classifications, reference data, and **point-in-time audit trails**. | | **Level 2** | **Processed Filings** | Access to converted content (Markdown/JSON) and full-text search capabilities. | | **Level 3** | **RAG / Agent** | Access to specific extracted financial line items (Revenue, EBITDA, etc.) mapped to standard taxonomies, and access to the conversational RAG agent. |  ### Rate Limiting To ensure stability, this API uses a dual-layer rate limit: 1.  **Burst Limit:** A short-term speed limit (e.g., 5 requests/second) to prevent system overload. 2.  **Quota Limit:** A monthly allowance of total requests based on your subscription plan.  Check the response headers `X-RateLimit-Burst-Limit` and `X-RateLimit-Monthly-Remaining` for your current status.  ### Authentication All API requests must be authenticated via the **X-API-Key** header. 

    The version of the OpenAPI document: 1.1.5
    Contact: api@financialreports.eu
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from financial_reports_generated_client.models.company_minimal import CompanyMinimal
from typing import Optional, Set
from typing_extensions import Self
from pydantic_core import to_jsonable_python

class ISIN(BaseModel):
    """
    ISIN
    """ # noqa: E501
    code: StrictStr = Field(description="The 12-character International Securities Identification Number.")
    is_primary: StrictBool = Field(description="Indicates if this is the primary ISIN for the company on this platform.")
    company: CompanyMinimal = Field(description="The company associated with this ISIN.")
    figi: StrictStr = Field(description="The 12-character Financial Instrument Global Identifier (FIGI) for this specific listing.")
    composite_figi: StrictStr = Field(description="The composite FIGI representing the instrument across all exchanges in a given country.")
    share_class_figi: StrictStr = Field(description="The share class FIGI representing the instrument globally, regardless of exchange.")
    security_type: StrictStr = Field(description="Primary security type classification (e.g., Common Stock, ETP, REIT).")
    security_type2: StrictStr = Field(description="Secondary security type classification providing additional granularity.")
    market_sector: StrictStr = Field(description="Market sector classification from OpenFIGI (e.g., Equity, Govt, Corp).")
    exch_code: StrictStr = Field(description="Exchange code where this security is listed (e.g., GY, US, LN).")
    figi_last_updated: Optional[datetime] = Field(description="Timestamp of the last successful FIGI data enrichment for this ISIN.")
    __properties: ClassVar[List[str]] = ["code", "is_primary", "company", "figi", "composite_figi", "share_class_figi", "security_type", "security_type2", "market_sector", "exch_code", "figi_last_updated"]

    model_config = ConfigDict(
        validate_by_name=True,
        validate_by_alias=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(to_jsonable_python(self.to_dict()))

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of ISIN from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "code",
            "is_primary",
            "company",
            "figi",
            "composite_figi",
            "share_class_figi",
            "security_type",
            "security_type2",
            "market_sector",
            "exch_code",
            "figi_last_updated",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of company
        if self.company:
            _dict['company'] = self.company.to_dict()
        # set to None if figi_last_updated (nullable) is None
        # and model_fields_set contains the field
        if self.figi_last_updated is None and "figi_last_updated" in self.model_fields_set:
            _dict['figi_last_updated'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of ISIN from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "code": obj.get("code"),
            "is_primary": obj.get("is_primary"),
            "company": CompanyMinimal.from_dict(obj["company"]) if obj.get("company") is not None else None,
            "figi": obj.get("figi"),
            "composite_figi": obj.get("composite_figi"),
            "share_class_figi": obj.get("share_class_figi"),
            "security_type": obj.get("security_type"),
            "security_type2": obj.get("security_type2"),
            "market_sector": obj.get("market_sector"),
            "exch_code": obj.get("exch_code"),
            "figi_last_updated": obj.get("figi_last_updated")
        })
        return _obj


