"""mindbodypublicapi.

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

# ruff: noqa: E501
from mindbodypublicapi.api_helper import APIHelper
from mindbodypublicapi.models.purchased_item import (
    PurchasedItem,
)
from mindbodypublicapi.models.sale_payment import (
    SalePayment,
)


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

    Contains the Sale details.

    Attributes:
        id (int): The sale ID.
        sale_date (datetime): The date the item was sold.
        sale_time (str): The time the item was sold.
        sale_date_time (datetime): The date and time the item was sold.
        original_sale_date_time (datetime): The date and time the item was sold
            originally.
        sales_rep_id (int): The sales representative ID
        client_id (str): The ID of the client who made the purchase.
        recipient_client_id (int): Recipient Client Id
        purchased_items (List[PurchasedItem]): Contains the `PurchasedItem` objects
            that describe the purchased items.
        location_id (int): The ID of the location where the sale takes place.
        payments (List[SalePayment]): Contains the `SalePayment` objects that
            describe the payments that contributed to this sale.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "id": "Id",
        "sale_date": "SaleDate",
        "sale_time": "SaleTime",
        "sale_date_time": "SaleDateTime",
        "original_sale_date_time": "OriginalSaleDateTime",
        "sales_rep_id": "SalesRepId",
        "client_id": "ClientId",
        "recipient_client_id": "RecipientClientId",
        "purchased_items": "PurchasedItems",
        "location_id": "LocationId",
        "payments": "Payments",
    }

    _optionals = [
        "id",
        "sale_date",
        "sale_time",
        "sale_date_time",
        "original_sale_date_time",
        "sales_rep_id",
        "client_id",
        "recipient_client_id",
        "purchased_items",
        "location_id",
        "payments",
    ]

    def __init__(
        self,
        id=APIHelper.SKIP,
        sale_date=APIHelper.SKIP,
        sale_time=APIHelper.SKIP,
        sale_date_time=APIHelper.SKIP,
        original_sale_date_time=APIHelper.SKIP,
        sales_rep_id=APIHelper.SKIP,
        client_id=APIHelper.SKIP,
        recipient_client_id=APIHelper.SKIP,
        purchased_items=APIHelper.SKIP,
        location_id=APIHelper.SKIP,
        payments=APIHelper.SKIP):
        """Initialize a Sale instance."""
        # Initialize members of the class
        if id is not APIHelper.SKIP:
            self.id = id
        if sale_date is not APIHelper.SKIP:
            self.sale_date =\
                 APIHelper.apply_datetime_converter(
                sale_date, APIHelper.RFC3339DateTime)\
                 if sale_date else None
        if sale_time is not APIHelper.SKIP:
            self.sale_time = sale_time
        if sale_date_time is not APIHelper.SKIP:
            self.sale_date_time =\
                 APIHelper.apply_datetime_converter(
                sale_date_time, APIHelper.RFC3339DateTime)\
                 if sale_date_time else None
        if original_sale_date_time is not APIHelper.SKIP:
            self.original_sale_date_time =\
                 APIHelper.apply_datetime_converter(
                original_sale_date_time, APIHelper.RFC3339DateTime)\
                 if original_sale_date_time else None
        if sales_rep_id is not APIHelper.SKIP:
            self.sales_rep_id = sales_rep_id
        if client_id is not APIHelper.SKIP:
            self.client_id = client_id
        if recipient_client_id is not APIHelper.SKIP:
            self.recipient_client_id = recipient_client_id
        if purchased_items is not APIHelper.SKIP:
            self.purchased_items = purchased_items
        if location_id is not APIHelper.SKIP:
            self.location_id = location_id
        if payments is not APIHelper.SKIP:
            self.payments = payments

    @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 APIHelper.SKIP
        sale_date = APIHelper.RFC3339DateTime.from_value(
            dictionary.get("SaleDate")).datetime\
            if dictionary.get("SaleDate") else APIHelper.SKIP
        sale_time =\
            dictionary.get("SaleTime")\
            if dictionary.get("SaleTime")\
                else APIHelper.SKIP
        sale_date_time = APIHelper.RFC3339DateTime.from_value(
            dictionary.get("SaleDateTime")).datetime\
            if dictionary.get("SaleDateTime") else APIHelper.SKIP
        original_sale_date_time = APIHelper.RFC3339DateTime.from_value(
            dictionary.get("OriginalSaleDateTime")).datetime\
            if dictionary.get("OriginalSaleDateTime") else APIHelper.SKIP
        sales_rep_id =\
            dictionary.get("SalesRepId")\
            if dictionary.get("SalesRepId")\
                else APIHelper.SKIP
        client_id =\
            dictionary.get("ClientId")\
            if dictionary.get("ClientId")\
                else APIHelper.SKIP
        recipient_client_id =\
            dictionary.get("RecipientClientId")\
            if dictionary.get("RecipientClientId")\
                else APIHelper.SKIP
        purchased_items = None
        if dictionary.get("PurchasedItems") is not None:
            purchased_items = [
                PurchasedItem.from_dictionary(x)
                    for x in dictionary.get("PurchasedItems")
            ]
        else:
            purchased_items = APIHelper.SKIP
        location_id =\
            dictionary.get("LocationId")\
            if dictionary.get("LocationId")\
                else APIHelper.SKIP
        payments = None
        if dictionary.get("Payments") is not None:
            payments = [
                SalePayment.from_dictionary(x)
                    for x in dictionary.get("Payments")
            ]
        else:
            payments = APIHelper.SKIP

        # Return an object of this model
        return cls(id,
                   sale_date,
                   sale_time,
                   sale_date_time,
                   original_sale_date_time,
                   sales_rep_id,
                   client_id,
                   recipient_client_id,
                   purchased_items,
                   location_id,
                   payments)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _id=(
            self.id
            if hasattr(self, "id")
            else None
        )
        _sale_date=(
            self.sale_date
            if hasattr(self, "sale_date")
            else None
        )
        _sale_time=(
            self.sale_time
            if hasattr(self, "sale_time")
            else None
        )
        _sale_date_time=(
            self.sale_date_time
            if hasattr(self, "sale_date_time")
            else None
        )
        _original_sale_date_time=(
            self.original_sale_date_time
            if hasattr(self, "original_sale_date_time")
            else None
        )
        _sales_rep_id=(
            self.sales_rep_id
            if hasattr(self, "sales_rep_id")
            else None
        )
        _client_id=(
            self.client_id
            if hasattr(self, "client_id")
            else None
        )
        _recipient_client_id=(
            self.recipient_client_id
            if hasattr(self, "recipient_client_id")
            else None
        )
        _purchased_items=(
            self.purchased_items
            if hasattr(self, "purchased_items")
            else None
        )
        _location_id=(
            self.location_id
            if hasattr(self, "location_id")
            else None
        )
        _payments=(
            self.payments
            if hasattr(self, "payments")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"id={_id!r}, "
            f"sale_date={_sale_date!r}, "
            f"sale_time={_sale_time!r}, "
            f"sale_date_time={_sale_date_time!r}, "
            f"original_sale_date_time={_original_sale_date_time!r}, "
            f"sales_rep_id={_sales_rep_id!r}, "
            f"client_id={_client_id!r}, "
            f"recipient_client_id={_recipient_client_id!r}, "
            f"purchased_items={_purchased_items!r}, "
            f"location_id={_location_id!r}, "
            f"payments={_payments!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _id=(
            self.id
            if hasattr(self, "id")
            else None
        )
        _sale_date=(
            self.sale_date
            if hasattr(self, "sale_date")
            else None
        )
        _sale_time=(
            self.sale_time
            if hasattr(self, "sale_time")
            else None
        )
        _sale_date_time=(
            self.sale_date_time
            if hasattr(self, "sale_date_time")
            else None
        )
        _original_sale_date_time=(
            self.original_sale_date_time
            if hasattr(self, "original_sale_date_time")
            else None
        )
        _sales_rep_id=(
            self.sales_rep_id
            if hasattr(self, "sales_rep_id")
            else None
        )
        _client_id=(
            self.client_id
            if hasattr(self, "client_id")
            else None
        )
        _recipient_client_id=(
            self.recipient_client_id
            if hasattr(self, "recipient_client_id")
            else None
        )
        _purchased_items=(
            self.purchased_items
            if hasattr(self, "purchased_items")
            else None
        )
        _location_id=(
            self.location_id
            if hasattr(self, "location_id")
            else None
        )
        _payments=(
            self.payments
            if hasattr(self, "payments")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"id={_id!s}, "
            f"sale_date={_sale_date!s}, "
            f"sale_time={_sale_time!s}, "
            f"sale_date_time={_sale_date_time!s}, "
            f"original_sale_date_time={_original_sale_date_time!s}, "
            f"sales_rep_id={_sales_rep_id!s}, "
            f"client_id={_client_id!s}, "
            f"recipient_client_id={_recipient_client_id!s}, "
            f"purchased_items={_purchased_items!s}, "
            f"location_id={_location_id!s}, "
            f"payments={_payments!s}, "
            f")"
        )
