# 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, StrictBool, StrictFloat, StrictInt, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from openapi_client.models.id_request import IdRequest
from typing import Optional, Set
from typing_extensions import Self

class LocationCreateRequest(BaseModel):
    """
    LocationCreateRequest
    """ # noqa: E501
    code: Annotated[str, Field(min_length=1, strict=True, max_length=255)]
    name: Annotated[str, Field(min_length=1, strict=True, max_length=255)]
    location_group: Optional[IdRequest] = Field(default=None, alias="locationGroup")
    city: Dict[str, Any]
    latitude: Optional[Union[StrictFloat, StrictInt]] = None
    longitude: Optional[Union[StrictFloat, StrictInt]] = None
    address: Optional[Annotated[str, Field(strict=True, max_length=65535)]] = None
    phone: Optional[Annotated[str, Field(strict=True, max_length=255)]] = Field(default=None, description="e.g. `+6281234567890`")
    zip_code: Optional[Annotated[str, Field(strict=True, max_length=5)]] = Field(default=None, description="Numeric", alias="zipCode")
    headquarter: StrictBool = Field(description="If value is true, will automatically update headquarter in company profile")
    __properties: ClassVar[List[str]] = ["code", "name", "locationGroup", "city", "latitude", "longitude", "address", "phone", "zipCode", "headquarter"]

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

        if not re.match(r"^[+]{1}[0-9-() ]+", value):
            raise ValueError(r"must validate the regular expression /^[+]{1}[0-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 LocationCreateRequest 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 location_group
        if self.location_group:
            _dict['locationGroup'] = self.location_group.to_dict()
        # override the default output from pydantic by calling `to_dict()` of city
        if self.city:
            _dict['city'] = self.city.to_dict()
        # set to None if latitude (nullable) is None
        # and model_fields_set contains the field
        if self.latitude is None and "latitude" in self.model_fields_set:
            _dict['latitude'] = None

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of LocationCreateRequest 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"),
            "name": obj.get("name"),
            "locationGroup": IdRequest.from_dict(obj["locationGroup"]) if obj.get("locationGroup") is not None else None,
            "city": IdRequest.from_dict(obj["city"]) if obj.get("city") is not None else None,
            "latitude": obj.get("latitude"),
            "longitude": obj.get("longitude"),
            "address": obj.get("address"),
            "phone": obj.get("phone"),
            "zipCode": obj.get("zipCode"),
            "headquarter": obj.get("headquarter")
        })
        return _obj


