# coding: utf-8

"""
    Financial Reports API

    API for accessing company filings, financial data, industry classifications, and related information.

    The version of the OpenAPI document: 1.0.0
    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 date, datetime
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List
from financial_reports_generated_client.models.company_minimal import CompanyMinimal
from financial_reports_generated_client.models.filing_type import FilingType
from financial_reports_generated_client.models.language import Language
from financial_reports_generated_client.models.source import Source
from typing import Optional, Set
from typing_extensions import Self

class Filing(BaseModel):
    """
    Serializer for regulatory filings.
    """ # noqa: E501
    id: StrictInt = Field(description="Unique identifier for the filing.")
    company: CompanyMinimal = Field(description="Basic details of the company that made the filing.")
    filing_type: FilingType = Field(description="Details of the filing type.")
    language: Language = Field(description="Language of the filing document.")
    filing_date: date = Field(description="The official date the document was filed.")
    title: StrictStr = Field(description="Title of the filing document.")
    added_to_platform: datetime = Field(description="Timestamp when the filing was added to our system (UTC).")
    updated_date: datetime = Field(description="Timestamp when the filing record was last updated (UTC).")
    dissemination_datetime: datetime = Field(description="Timestamp when the filing was disseminated by the source (UTC).")
    release_datetime: datetime = Field(description="Timestamp when the filing was released (e.g., for press releases) (UTC).")
    source: Source = Field(description="Source from which the filing was obtained.")
    document: StrictStr = Field(description="URL link to the primary filing document (e.g., PDF, HTML).")
    year: StrictInt = Field(description="The financial year the filing pertains to.")
    __properties: ClassVar[List[str]] = ["id", "company", "filing_type", "language", "filing_date", "title", "added_to_platform", "updated_date", "dissemination_datetime", "release_datetime", "source", "document", "year"]

    model_config = ConfigDict(
        populate_by_name=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"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of Filing 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "id",
            "company",
            "filing_type",
            "language",
            "filing_date",
            "title",
            "added_to_platform",
            "updated_date",
            "dissemination_datetime",
            "release_datetime",
            "source",
            "document",
            "year",
        ])

        _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()
        # override the default output from pydantic by calling `to_dict()` of filing_type
        if self.filing_type:
            _dict['filing_type'] = self.filing_type.to_dict()
        # override the default output from pydantic by calling `to_dict()` of language
        if self.language:
            _dict['language'] = self.language.to_dict()
        # override the default output from pydantic by calling `to_dict()` of source
        if self.source:
            _dict['source'] = self.source.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "company": CompanyMinimal.from_dict(obj["company"]) if obj.get("company") is not None else None,
            "filing_type": FilingType.from_dict(obj["filing_type"]) if obj.get("filing_type") is not None else None,
            "language": Language.from_dict(obj["language"]) if obj.get("language") is not None else None,
            "filing_date": obj.get("filing_date"),
            "title": obj.get("title"),
            "added_to_platform": obj.get("added_to_platform"),
            "updated_date": obj.get("updated_date"),
            "dissemination_datetime": obj.get("dissemination_datetime"),
            "release_datetime": obj.get("release_datetime"),
            "source": Source.from_dict(obj["source"]) if obj.get("source") is not None else None,
            "document": obj.get("document"),
            "year": obj.get("year")
        })
        return _obj


