# coding: utf-8

"""
    CATAPA API

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

    The version of the OpenAPI document: 1.0.0
    Contact: support@catapa.com
    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
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from openapi_client.models.id_code_name_response import IdCodeNameResponse
from openapi_client.models.organization_history_hierarchy_response import OrganizationHistoryHierarchyResponse
from typing import Optional, Set
from typing_extensions import Self

class OrganizationHistoryResponse(BaseModel):
    """
    OrganizationHistoryResponse
    """ # noqa: E501
    id: Optional[StrictStr] = None
    code: Optional[StrictStr] = None
    name: Optional[StrictStr] = None
    organization: Optional[IdCodeNameResponse] = None
    company: Optional[IdCodeNameResponse] = None
    type: Optional[StrictStr] = None
    organization_hierarchy: Optional[OrganizationHistoryHierarchyResponse] = Field(default=None, alias="organizationHierarchy")
    organization_group: Optional[IdCodeNameResponse] = Field(default=None, alias="organizationGroup")
    effective_date: Optional[date] = Field(default=None, alias="effectiveDate")
    end_date: Optional[date] = Field(default=None, alias="endDate")
    __properties: ClassVar[List[str]] = ["id", "code", "name", "organization", "company", "type", "organizationHierarchy", "organizationGroup", "effectiveDate", "endDate"]

    @field_validator('type')
    def type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['STRUCTURAL', 'FUNCTIONAL']):
            raise ValueError("must be one of enum values ('STRUCTURAL', 'FUNCTIONAL')")
        return value

    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 OrganizationHistoryResponse 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 organization
        if self.organization:
            _dict['organization'] = self.organization.to_dict()
        # 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 organization_hierarchy
        if self.organization_hierarchy:
            _dict['organizationHierarchy'] = self.organization_hierarchy.to_dict()
        # override the default output from pydantic by calling `to_dict()` of organization_group
        if self.organization_group:
            _dict['organizationGroup'] = self.organization_group.to_dict()
        # set to None if end_date (nullable) is None
        # and model_fields_set contains the field
        if self.end_date is None and "end_date" in self.model_fields_set:
            _dict['endDate'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of OrganizationHistoryResponse 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"),
            "code": obj.get("code"),
            "name": obj.get("name"),
            "organization": IdCodeNameResponse.from_dict(obj["organization"]) if obj.get("organization") is not None else None,
            "company": IdCodeNameResponse.from_dict(obj["company"]) if obj.get("company") is not None else None,
            "type": obj.get("type"),
            "organizationHierarchy": OrganizationHistoryHierarchyResponse.from_dict(obj["organizationHierarchy"]) if obj.get("organizationHierarchy") is not None else None,
            "organizationGroup": IdCodeNameResponse.from_dict(obj["organizationGroup"]) if obj.get("organizationGroup") is not None else None,
            "effectiveDate": obj.get("effectiveDate"),
            "endDate": obj.get("endDate")
        })
        return _obj


