# 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_create_waybill_created_emails_language import (
    ExternalAPIOriginCreateWaybillCreatedEmailsLanguage,
)
from pywaybiller.openapi_client.models.geo_location_request import GeoLocationRequest


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

    name: Optional[Annotated[str, Field(min_length=1, strict=True)]] = None
    location: Optional[GeoLocationRequest] = None
    assortments: Optional[List[ExternalAPIOriginAssortmentRequest]] = None
    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] = False
    active: Optional[StrictBool] = True
    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(min_length=1, 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)]] = (
        None
    )
    representative_name: Optional[Annotated[str, Field(strict=True, max_length=64)]] = (
        None
    )
    representative_phone: Optional[
        Annotated[str, Field(strict=True, max_length=128)]
    ] = None
    waybill_created_emails: Optional[
        List[Annotated[str, Field(min_length=1, strict=True)]]
    ] = Field(
        default=None,
        description="E-mail addresses, where you want to receive notification when waybill is created.",
    )
    waybill_accepted_emails: Optional[
        List[Annotated[str, Field(min_length=1, strict=True)]]
    ] = Field(
        default=None,
        description="E-mail addresses, where you want to receive notification when waybill is accepted.",
    )
    waybill_reached_destination_emails: Optional[
        List[Annotated[str, Field(min_length=1, strict=True)]]
    ] = Field(
        default=None,
        description="E-mail addresses, where you want to receive notification when waybill has arrived at destination.",
    )
    transport_order_created_emails: Optional[
        List[Annotated[str, Field(min_length=1, strict=True)]]
    ] = Field(
        default=None,
        description="E-mail addresses, where you want to receive notification when transport order is created.",
    )
    waybill_created_emails_language: Optional[
        ExternalAPIOriginCreateWaybillCreatedEmailsLanguage
    ] = None
    waybill_accepted_emails_language: Optional[
        ExternalAPIOriginCreateWaybillCreatedEmailsLanguage
    ] = None
    waybill_reached_destination_emails_language: Optional[
        ExternalAPIOriginCreateWaybillCreatedEmailsLanguage
    ] = None
    transport_order_created_emails_language: Optional[
        ExternalAPIOriginCreateWaybillCreatedEmailsLanguage
    ] = None
    feature_single_transport_order_per_truck: Optional[StrictBool] = Field(
        default=False,
        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=False,
        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=False,
            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()
            )
        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": GeoLocationRequest.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") if obj.get("public") is not None else False,
                "active": obj.get("active") if obj.get("active") is not None else True,
                "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": ExternalAPIOriginCreateWaybillCreatedEmailsLanguage.from_dict(
                    obj["waybill_created_emails_language"]
                )
                if obj.get("waybill_created_emails_language") is not None
                else None,
                "waybill_accepted_emails_language": ExternalAPIOriginCreateWaybillCreatedEmailsLanguage.from_dict(
                    obj["waybill_accepted_emails_language"]
                )
                if obj.get("waybill_accepted_emails_language") is not None
                else None,
                "waybill_reached_destination_emails_language": ExternalAPIOriginCreateWaybillCreatedEmailsLanguage.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": ExternalAPIOriginCreateWaybillCreatedEmailsLanguage.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"
                )
                if obj.get("feature_single_transport_order_per_truck") is not None
                else False,
                "feature_waybill_dispatched_amounts_changing_disabled": obj.get(
                    "feature_waybill_dispatched_amounts_changing_disabled"
                )
                if obj.get("feature_waybill_dispatched_amounts_changing_disabled")
                is not None
                else False,
                "feature_waybill_destination_changing_disabled_for_drivers": obj.get(
                    "feature_waybill_destination_changing_disabled_for_drivers"
                )
                if obj.get("feature_waybill_destination_changing_disabled_for_drivers")
                is not None
                else False,
            }
        )
        return _obj
