"""cellpointapi.

This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
"""

# ruff: noqa: E501
from cellpointapi.api_helper import APIHelper
from cellpointapi.models.airport import Airport
from cellpointapi.models.carrier import Carrier
from cellpointapi.models.codeshare import Codeshare


class TravelLeg(object):
    """Implementation of the 'TravelLeg' model.

    Leg in the journey.

    Attributes:
        id (str): Identifier for leg that is unique within this order. This
            identifier should be used for any reference to this travel leg elsewhere,
            such as linking this specific leg to an ancillary in the price summary.
            How this identifier is generated is up to the merchant, as long as it is
            unique within the order.
        origin (Airport): The travel airport details.
        destination (Airport): The travel airport details.
        departure_time (datetime): The date and time of departure.
        arrival_time (datetime): The date and time of arrival.
        booking_class_code (str): IATA code for the class of service for this leg of
            the trip, such as coach or first class.
        service_level (str): Service level purchased, i.e. Economy, Business, First.
        carrier (Carrier): Carrier of this flight.  > In case of codeshare, this is
            the marketing flight number.
        flight_number (str): Number assigned to this individual flight.  > In case of
            codeshare, this is the marketing flight number.
        codeshare (Codeshare): Information about codesharing agreement for this
            flight.
        stop_over_allowed (bool): The model property of type bool.
        additional_properties (Dict[str, Any]): The additional properties for the
            model.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "id": "id",
        "origin": "origin",
        "destination": "destination",
        "departure_time": "departureTime",
        "arrival_time": "arrivalTime",
        "booking_class_code": "bookingClassCode",
        "service_level": "serviceLevel",
        "carrier": "carrier",
        "flight_number": "flightNumber",
        "codeshare": "codeshare",
        "stop_over_allowed": "stopOverAllowed",
    }

    _optionals = [
        "booking_class_code",
        "service_level",
        "carrier",
        "flight_number",
        "codeshare",
        "stop_over_allowed",
    ]

    def __init__(
        self,
        id=None,
        origin=None,
        destination=None,
        departure_time=None,
        arrival_time=None,
        booking_class_code=APIHelper.SKIP,
        service_level=APIHelper.SKIP,
        carrier=APIHelper.SKIP,
        flight_number=APIHelper.SKIP,
        codeshare=APIHelper.SKIP,
        stop_over_allowed=APIHelper.SKIP,
        additional_properties=None):
        """Initialize a TravelLeg instance."""
        # Initialize members of the class
        self.id = id
        self.origin = origin
        self.destination = destination
        self.departure_time =\
             APIHelper.apply_datetime_converter(
            departure_time, APIHelper.RFC3339DateTime)\
             if departure_time else None
        self.arrival_time =\
             APIHelper.apply_datetime_converter(
            arrival_time, APIHelper.RFC3339DateTime)\
             if arrival_time else None
        if booking_class_code is not APIHelper.SKIP:
            self.booking_class_code = booking_class_code
        if service_level is not APIHelper.SKIP:
            self.service_level = service_level
        if carrier is not APIHelper.SKIP:
            self.carrier = carrier
        if flight_number is not APIHelper.SKIP:
            self.flight_number = flight_number
        if codeshare is not APIHelper.SKIP:
            self.codeshare = codeshare
        if stop_over_allowed is not APIHelper.SKIP:
            self.stop_over_allowed = stop_over_allowed

        # Add additional model properties to the instance
        if additional_properties is None:
            additional_properties = {}
        self.additional_properties = additional_properties

    @classmethod
    def from_dictionary(cls,
                        dictionary):
        """Create an instance of this model from a dictionary

        Args:
            dictionary (dictionary): A dictionary representation of the object
            as obtained from the deserialization of the server's response. The
            keys MUST match property names in the API description.

        Returns:
            object: An instance of this structure class.

        """
        if not isinstance(dictionary, dict) or dictionary is None:
            return None

        # Extract variables from the dictionary
        id =\
            dictionary.get("id")\
            if dictionary.get("id")\
                else None
        origin =\
            Airport.from_dictionary(
                dictionary.get("origin"))\
                if dictionary.get("origin") else None
        destination =\
            Airport.from_dictionary(
                dictionary.get("destination"))\
                if dictionary.get("destination") else None
        departure_time = APIHelper.RFC3339DateTime.from_value(
            dictionary.get("departureTime")).datetime\
            if dictionary.get("departureTime") else None
        arrival_time = APIHelper.RFC3339DateTime.from_value(
            dictionary.get("arrivalTime")).datetime\
            if dictionary.get("arrivalTime") else None
        booking_class_code =\
            dictionary.get("bookingClassCode")\
            if dictionary.get("bookingClassCode")\
                else APIHelper.SKIP
        service_level =\
            dictionary.get("serviceLevel")\
            if dictionary.get("serviceLevel")\
                else APIHelper.SKIP
        carrier =\
            Carrier.from_dictionary(
                dictionary.get("carrier"))\
                if "carrier" in dictionary.keys()\
                else APIHelper.SKIP
        flight_number =\
            dictionary.get("flightNumber")\
            if dictionary.get("flightNumber")\
                else APIHelper.SKIP
        codeshare =\
            Codeshare.from_dictionary(
                dictionary.get("codeshare"))\
                if "codeshare" in dictionary.keys()\
                else APIHelper.SKIP
        stop_over_allowed =\
            dictionary.get("stopOverAllowed")\
            if "stopOverAllowed" in dictionary.keys()\
                else APIHelper.SKIP

        additional_properties = APIHelper.get_additional_properties(
            dictionary={k: v for k, v in dictionary.items()
                        if k not in cls._names.values()},
            unboxing_function=lambda value: value)

        # Return an object of this model
        return cls(id,
                   origin,
                   destination,
                   departure_time,
                   arrival_time,
                   booking_class_code,
                   service_level,
                   carrier,
                   flight_number,
                   codeshare,
                   stop_over_allowed,
                   additional_properties)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _id=self.id
        _origin=self.origin
        _destination=self.destination
        _departure_time=self.departure_time
        _arrival_time=self.arrival_time
        _booking_class_code=(
            self.booking_class_code
            if hasattr(self, "booking_class_code")
            else None
        )
        _service_level=(
            self.service_level
            if hasattr(self, "service_level")
            else None
        )
        _carrier=(
            self.carrier
            if hasattr(self, "carrier")
            else None
        )
        _flight_number=(
            self.flight_number
            if hasattr(self, "flight_number")
            else None
        )
        _codeshare=(
            self.codeshare
            if hasattr(self, "codeshare")
            else None
        )
        _stop_over_allowed=(
            self.stop_over_allowed
            if hasattr(self, "stop_over_allowed")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"id={_id!r}, "
            f"origin={_origin!r}, "
            f"destination={_destination!r}, "
            f"departure_time={_departure_time!r}, "
            f"arrival_time={_arrival_time!r}, "
            f"booking_class_code={_booking_class_code!r}, "
            f"service_level={_service_level!r}, "
            f"carrier={_carrier!r}, "
            f"flight_number={_flight_number!r}, "
            f"codeshare={_codeshare!r}, "
            f"stop_over_allowed={_stop_over_allowed!r}, "
            f"additional_properties={_additional_properties!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _id=self.id
        _origin=self.origin
        _destination=self.destination
        _departure_time=self.departure_time
        _arrival_time=self.arrival_time
        _booking_class_code=(
            self.booking_class_code
            if hasattr(self, "booking_class_code")
            else None
        )
        _service_level=(
            self.service_level
            if hasattr(self, "service_level")
            else None
        )
        _carrier=(
            self.carrier
            if hasattr(self, "carrier")
            else None
        )
        _flight_number=(
            self.flight_number
            if hasattr(self, "flight_number")
            else None
        )
        _codeshare=(
            self.codeshare
            if hasattr(self, "codeshare")
            else None
        )
        _stop_over_allowed=(
            self.stop_over_allowed
            if hasattr(self, "stop_over_allowed")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"id={_id!s}, "
            f"origin={_origin!s}, "
            f"destination={_destination!s}, "
            f"departure_time={_departure_time!s}, "
            f"arrival_time={_arrival_time!s}, "
            f"booking_class_code={_booking_class_code!s}, "
            f"service_level={_service_level!s}, "
            f"carrier={_carrier!s}, "
            f"flight_number={_flight_number!s}, "
            f"codeshare={_codeshare!s}, "
            f"stop_over_allowed={_stop_over_allowed!s}, "
            f"additional_properties={_additional_properties!s}, "
            f")"
        )
