# 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 pydantic import BaseModel, ConfigDict, Field, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from openapi_client.models.company_detail_time_zone_request import CompanyDetailTimeZoneRequest
from openapi_client.models.id_request import IdRequest
from typing import Optional, Set
from typing_extensions import Self

class CompanyDetailRequest(BaseModel):
    """
    The Content-Type must be `application/json`
    """ # noqa: E501
    name: Annotated[str, Field(min_length=1, strict=True, max_length=255)]
    code: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=255)]] = None
    website: Optional[Annotated[str, Field(min_length=3, strict=True, max_length=80)]] = None
    siup: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=255)]] = Field(default=None, description="Alphanumeric, hyphen (-), slash (/), period (.), and space")
    tdp: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=255)]] = Field(default=None, description="Alphanumeric, hyphen (-), slash (/), period (.), and space")
    time_zone: CompanyDetailTimeZoneRequest = Field(alias="timeZone")
    email: Annotated[str, Field(strict=True, max_length=255)]
    company_superior: Optional[IdRequest] = Field(default=None, alias="companySuperior")
    location: IdRequest
    __properties: ClassVar[List[str]] = ["name", "code", "website", "siup", "tdp", "timeZone", "email", "companySuperior", "location"]

    @field_validator('siup')
    def siup_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"[a-zA-Z0-9-\/. ]+", value):
            raise ValueError(r"must validate the regular expression /[a-zA-Z0-9-\/. ]+/")
        return value

    @field_validator('tdp')
    def tdp_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"[a-zA-Z0-9-\/. ]+", value):
            raise ValueError(r"must validate the regular expression /[a-zA-Z0-9-\/. ]+/")
        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 CompanyDetailRequest 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 time_zone
        if self.time_zone:
            _dict['timeZone'] = self.time_zone.to_dict()
        # override the default output from pydantic by calling `to_dict()` of company_superior
        if self.company_superior:
            _dict['companySuperior'] = self.company_superior.to_dict()
        # override the default output from pydantic by calling `to_dict()` of location
        if self.location:
            _dict['location'] = self.location.to_dict()
        # set to None if code (nullable) is None
        # and model_fields_set contains the field
        if self.code is None and "code" in self.model_fields_set:
            _dict['code'] = None

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "name": obj.get("name"),
            "code": obj.get("code"),
            "website": obj.get("website"),
            "siup": obj.get("siup"),
            "tdp": obj.get("tdp"),
            "timeZone": CompanyDetailTimeZoneRequest.from_dict(obj["timeZone"]) if obj.get("timeZone") is not None else None,
            "email": obj.get("email"),
            "companySuperior": IdRequest.from_dict(obj["companySuperior"]) if obj.get("companySuperior") is not None else None,
            "location": IdRequest.from_dict(obj["location"]) if obj.get("location") is not None else None
        })
        return _obj


