# coding: utf-8

"""
Waybiller External API - with fixes

The **Waybiller External API** is a feature that allows companies to access **Waybiller** data as JSON objects and create **Waybiller** instances out of their own data.  To make integration easier for the companies, the external API provides mapping support - it is possible to create company-specific mappings for object identifiers (such as destination and origin).  These mappings will be used for representing companies data from external API, and for converting the values during the creation of **Waybiller** instances (such as transport orders and waybills).  Most of the API responses contain mapped values, which may be null if the company doesn't have a mapping for this object.  Unique **Waybiller** identifiers and values can be accessed via the `raw_data` key.  The API is HTTPS and JSON based.  ### Pagination  By default, list endpoint responses are presented in pages of 30 items.  It is possible to control the page size using the `limit` parameter: `/external-api/<some-list-endpoint>/?limit=<number>`, where `<number>` is an integer between 1 and 1000.

The version of the OpenAPI document: v1
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
"""  # noqa: E501

from __future__ import annotations

import json
import pprint
import re  # noqa: F401
from typing import Any, ClassVar, Dict, List, Optional, Set

from pydantic import BaseModel, ConfigDict, Field, StrictBool
from typing_extensions import Annotated, Self

from pywaybiller.openapi_client.models.external_api_holding_base_request import (
    ExternalAPIHoldingBaseRequest,
)
from pywaybiller.openapi_client.models.external_api_origin_assortment_request import (
    ExternalAPIOriginAssortmentRequest,
)
from pywaybiller.openapi_client.models.external_api_origin_location_request import (
    ExternalAPIOriginLocationRequest,
)
from pywaybiller.openapi_client.models.external_api_origin_update_waybill_created_emails_language import (
    ExternalAPIOriginUpdateWaybillCreatedEmailsLanguage,
)


class ExternalAPIOriginUpdateRequest(BaseModel):
    """
    ExternalAPIOriginUpdateRequest
    """  # noqa: E501

    name: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=255)]] = (
        Field(default=None, description="Name of the origin")
    )
    location: Optional[ExternalAPIOriginLocationRequest] = Field(
        default=None, description="Physical location of the origin"
    )
    assortments: Optional[List[ExternalAPIOriginAssortmentRequest]] = Field(
        default=None, description="List of assortments available at the origin"
    )
    partner_companies: Optional[
        List[Annotated[str, Field(min_length=1, strict=True)]]
    ] = Field(default=None, description="List of registry codes of partner companies")
    public: Optional[StrictBool] = Field(
        default=None,
        description="Indicates whether the origin is visible to all companies or only to the owner company and authorized partners",
    )
    active: Optional[StrictBool] = Field(
        default=None,
        description="Indicates whether the origin is currently active and available for use",
    )
    holding_base: Optional[ExternalAPIHoldingBaseRequest] = Field(
        default=None,
        description="Holding base data is provided as is, in internal WB format. It may change at any time without warning and may have a different schema for old and new origins",
    )
    cadaster_number: Optional[Annotated[str, Field(strict=True, max_length=500)]] = (
        Field(
            default=None,
            description="Cadaster number of the origin in free form. Required if holding base is sent",
        )
    )
    extra_information: Optional[Annotated[str, Field(strict=True, max_length=254)]] = (
        Field(
            default=None,
            description="Additional information about the origin that doesn't fit in other fields",
        )
    )
    representative_name: Optional[Annotated[str, Field(strict=True, max_length=64)]] = (
        Field(default=None, description="Name of the person representing this origin")
    )
    representative_phone: Optional[
        Annotated[str, Field(strict=True, max_length=128)]
    ] = Field(
        default=None, description="Contact phone number for the origin representative"
    )
    waybill_created_emails: Optional[
        List[Annotated[str, Field(strict=True, max_length=254)]]
    ] = Field(
        default=None,
        description="E-mail addresses where notifications will be sent when a waybill is created",
    )
    waybill_accepted_emails: Optional[
        List[Annotated[str, Field(strict=True, max_length=254)]]
    ] = Field(
        default=None,
        description="E-mail addresses where notifications will be sent when a waybill is accepted",
    )
    waybill_reached_destination_emails: Optional[
        List[Annotated[str, Field(strict=True, max_length=254)]]
    ] = Field(
        default=None,
        description="E-mail addresses where notifications will be sent when a waybill reaches its destination",
    )
    transport_order_created_emails: Optional[
        List[Annotated[str, Field(strict=True, max_length=254)]]
    ] = Field(
        default=None,
        description="E-mail addresses where notifications will be sent when a transport order is created",
    )
    waybill_created_emails_language: Optional[
        ExternalAPIOriginUpdateWaybillCreatedEmailsLanguage
    ] = None
    waybill_accepted_emails_language: Optional[
        ExternalAPIOriginUpdateWaybillCreatedEmailsLanguage
    ] = None
    waybill_reached_destination_emails_language: Optional[
        ExternalAPIOriginUpdateWaybillCreatedEmailsLanguage
    ] = None
    transport_order_created_emails_language: Optional[
        ExternalAPIOriginUpdateWaybillCreatedEmailsLanguage
    ] = None
    feature_single_transport_order_per_truck: Optional[StrictBool] = Field(
        default=None,
        description="Managers are not allowed to create transport orders for a vehicle if there is an active transport order for the vehicle from this origin",
    )
    feature_waybill_dispatched_amounts_changing_disabled: Optional[StrictBool] = Field(
        default=None,
        description="Drivers and receivers are not allowed to change dispatched amounts for waybills from this origin",
    )
    feature_waybill_destination_changing_disabled_for_drivers: Optional[StrictBool] = (
        Field(
            default=None,
            description="Drivers are not allowed to change the destination of waybills from this origin",
        )
    )
    __properties: ClassVar[List[str]] = [
        "name",
        "location",
        "assortments",
        "partner_companies",
        "public",
        "active",
        "holding_base",
        "cadaster_number",
        "extra_information",
        "representative_name",
        "representative_phone",
        "waybill_created_emails",
        "waybill_accepted_emails",
        "waybill_reached_destination_emails",
        "transport_order_created_emails",
        "waybill_created_emails_language",
        "waybill_accepted_emails_language",
        "waybill_reached_destination_emails_language",
        "transport_order_created_emails_language",
        "feature_single_transport_order_per_truck",
        "feature_waybill_dispatched_amounts_changing_disabled",
        "feature_waybill_destination_changing_disabled_for_drivers",
    ]

    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 ExternalAPIOriginUpdateRequest 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
        if self.location:
            _dict["location"] = self.location.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in assortments (list)
        _items = []
        if self.assortments:
            for _item_assortments in self.assortments:
                if _item_assortments:
                    _items.append(_item_assortments.to_dict())
            _dict["assortments"] = _items
        # override the default output from pydantic by calling `to_dict()` of holding_base
        if self.holding_base:
            _dict["holding_base"] = self.holding_base.to_dict()
        # override the default output from pydantic by calling `to_dict()` of waybill_created_emails_language
        if self.waybill_created_emails_language:
            _dict["waybill_created_emails_language"] = (
                self.waybill_created_emails_language.to_dict()
            )
        # override the default output from pydantic by calling `to_dict()` of waybill_accepted_emails_language
        if self.waybill_accepted_emails_language:
            _dict["waybill_accepted_emails_language"] = (
                self.waybill_accepted_emails_language.to_dict()
            )
        # override the default output from pydantic by calling `to_dict()` of waybill_reached_destination_emails_language
        if self.waybill_reached_destination_emails_language:
            _dict["waybill_reached_destination_emails_language"] = (
                self.waybill_reached_destination_emails_language.to_dict()
            )
        # override the default output from pydantic by calling `to_dict()` of transport_order_created_emails_language
        if self.transport_order_created_emails_language:
            _dict["transport_order_created_emails_language"] = (
                self.transport_order_created_emails_language.to_dict()
            )
        # set to None if waybill_created_emails (nullable) is None
        # and model_fields_set contains the field
        if (
            self.waybill_created_emails is None
            and "waybill_created_emails" in self.model_fields_set
        ):
            _dict["waybill_created_emails"] = None

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of ExternalAPIOriginUpdateRequest 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"),
                "location": ExternalAPIOriginLocationRequest.from_dict(obj["location"])
                if obj.get("location") is not None
                else None,
                "assortments": [
                    ExternalAPIOriginAssortmentRequest.from_dict(_item)
                    for _item in obj["assortments"]
                ]
                if obj.get("assortments") is not None
                else None,
                "partner_companies": obj.get("partner_companies"),
                "public": obj.get("public"),
                "active": obj.get("active"),
                "holding_base": ExternalAPIHoldingBaseRequest.from_dict(
                    obj["holding_base"]
                )
                if obj.get("holding_base") is not None
                else None,
                "cadaster_number": obj.get("cadaster_number"),
                "extra_information": obj.get("extra_information"),
                "representative_name": obj.get("representative_name"),
                "representative_phone": obj.get("representative_phone"),
                "waybill_created_emails": obj.get("waybill_created_emails"),
                "waybill_accepted_emails": obj.get("waybill_accepted_emails"),
                "waybill_reached_destination_emails": obj.get(
                    "waybill_reached_destination_emails"
                ),
                "transport_order_created_emails": obj.get(
                    "transport_order_created_emails"
                ),
                "waybill_created_emails_language": ExternalAPIOriginUpdateWaybillCreatedEmailsLanguage.from_dict(
                    obj["waybill_created_emails_language"]
                )
                if obj.get("waybill_created_emails_language") is not None
                else None,
                "waybill_accepted_emails_language": ExternalAPIOriginUpdateWaybillCreatedEmailsLanguage.from_dict(
                    obj["waybill_accepted_emails_language"]
                )
                if obj.get("waybill_accepted_emails_language") is not None
                else None,
                "waybill_reached_destination_emails_language": ExternalAPIOriginUpdateWaybillCreatedEmailsLanguage.from_dict(
                    obj["waybill_reached_destination_emails_language"]
                )
                if obj.get("waybill_reached_destination_emails_language") is not None
                else None,
                "transport_order_created_emails_language": ExternalAPIOriginUpdateWaybillCreatedEmailsLanguage.from_dict(
                    obj["transport_order_created_emails_language"]
                )
                if obj.get("transport_order_created_emails_language") is not None
                else None,
                "feature_single_transport_order_per_truck": obj.get(
                    "feature_single_transport_order_per_truck"
                ),
                "feature_waybill_dispatched_amounts_changing_disabled": obj.get(
                    "feature_waybill_dispatched_amounts_changing_disabled"
                ),
                "feature_waybill_destination_changing_disabled_for_drivers": obj.get(
                    "feature_waybill_destination_changing_disabled_for_drivers"
                ),
            }
        )
        return _obj
