# coding: utf-8

"""
    SRO Master API

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 0.1.37
    Contact: info@nexium.me
    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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from sromaster.models.organization_short_schema import OrganizationShortSchema
from sromaster.models.smr_contratcs_contract_status import SMRContratcsContractStatus
from sromaster.models.smr_contratcs_email_search_status import SMRContratcsEmailSearchStatus
from sromaster.models.smr_contratcs_message_status import SMRContratcsMessageStatus
from sromaster.models.smr_contratcs_result import SMRContratcsResult
from sromaster.models.smr_contratcs_status import SMRContratcsStatus
from typing import Optional, Set
from typing_extensions import Self
from pydantic_core import to_jsonable_python

class SMRContratcsOut(BaseModel):
    """
    SMRContratcsOut
    """ # noqa: E501
    id: StrictInt
    organisation: Optional[OrganizationShortSchema] = None
    agreement_number: Optional[StrictStr] = None
    url: Optional[StrictStr] = None
    commercial_offer_id: Optional[StrictInt] = None
    invoice_id: Optional[StrictInt] = None
    posting_date: Optional[date] = None
    contract_date: Optional[date] = None
    email_search_status: Optional[SMRContratcsEmailSearchStatus] = None
    message_status: Optional[SMRContratcsMessageStatus] = None
    status: Optional[SMRContratcsStatus] = None
    contract_status: Optional[SMRContratcsContractStatus] = None
    result: SMRContratcsResult
    created_at: datetime
    updated_at: datetime
    __properties: ClassVar[List[str]] = ["id", "organisation", "agreement_number", "url", "commercial_offer_id", "invoice_id", "posting_date", "contract_date", "email_search_status", "message_status", "status", "contract_status", "result", "created_at", "updated_at"]

    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 SMRContratcsOut 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.
        """
        excluded_fields: Set[str] = set([
        ])

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

        # set to None if agreement_number (nullable) is None
        # and model_fields_set contains the field
        if self.agreement_number is None and "agreement_number" in self.model_fields_set:
            _dict['agreement_number'] = None

        # set to None if url (nullable) is None
        # and model_fields_set contains the field
        if self.url is None and "url" in self.model_fields_set:
            _dict['url'] = None

        # set to None if commercial_offer_id (nullable) is None
        # and model_fields_set contains the field
        if self.commercial_offer_id is None and "commercial_offer_id" in self.model_fields_set:
            _dict['commercial_offer_id'] = None

        # set to None if invoice_id (nullable) is None
        # and model_fields_set contains the field
        if self.invoice_id is None and "invoice_id" in self.model_fields_set:
            _dict['invoice_id'] = None

        # set to None if posting_date (nullable) is None
        # and model_fields_set contains the field
        if self.posting_date is None and "posting_date" in self.model_fields_set:
            _dict['posting_date'] = None

        # set to None if contract_date (nullable) is None
        # and model_fields_set contains the field
        if self.contract_date is None and "contract_date" in self.model_fields_set:
            _dict['contract_date'] = None

        # set to None if email_search_status (nullable) is None
        # and model_fields_set contains the field
        if self.email_search_status is None and "email_search_status" in self.model_fields_set:
            _dict['email_search_status'] = None

        # set to None if message_status (nullable) is None
        # and model_fields_set contains the field
        if self.message_status is None and "message_status" in self.model_fields_set:
            _dict['message_status'] = None

        # set to None if status (nullable) is None
        # and model_fields_set contains the field
        if self.status is None and "status" in self.model_fields_set:
            _dict['status'] = None

        # set to None if contract_status (nullable) is None
        # and model_fields_set contains the field
        if self.contract_status is None and "contract_status" in self.model_fields_set:
            _dict['contract_status'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of SMRContratcsOut 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"),
            "organisation": OrganizationShortSchema.from_dict(obj["organisation"]) if obj.get("organisation") is not None else None,
            "agreement_number": obj.get("agreement_number"),
            "url": obj.get("url"),
            "commercial_offer_id": obj.get("commercial_offer_id"),
            "invoice_id": obj.get("invoice_id"),
            "posting_date": obj.get("posting_date"),
            "contract_date": obj.get("contract_date"),
            "email_search_status": obj.get("email_search_status"),
            "message_status": obj.get("message_status"),
            "status": obj.get("status"),
            "contract_status": obj.get("contract_status"),
            "result": obj.get("result"),
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at")
        })
        return _obj


