"""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.commission_detail import (
    CommissionDetail,
)


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

    Attributes:
        staff_id (int): The ID of the staff member who earned commissions.
        sale_date_time (datetime): The date and time when the sale occurred.
        sale_id (int): The sale’s ID.
        sale_type (str): The Sales type. When this is "Purchase" indicates that this
            sale paid commission to a staff. When this is "Return"
        product_id (int): The product ID of the item for which the staff earned
            commissions.
        earnings_details (List[CommissionDetail]): Contains information about which
            commissions the staff earned for this item.
        earnings (float): The total commissions earned by the staff for this item.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "staff_id": "StaffId",
        "sale_date_time": "SaleDateTime",
        "sale_id": "SaleId",
        "sale_type": "SaleType",
        "product_id": "ProductId",
        "earnings_details": "EarningsDetails",
        "earnings": "Earnings",
    }

    _optionals = [
        "staff_id",
        "sale_date_time",
        "sale_id",
        "sale_type",
        "product_id",
        "earnings_details",
        "earnings",
    ]

    def __init__(
        self,
        staff_id=APIHelper.SKIP,
        sale_date_time=APIHelper.SKIP,
        sale_id=APIHelper.SKIP,
        sale_type=APIHelper.SKIP,
        product_id=APIHelper.SKIP,
        earnings_details=APIHelper.SKIP,
        earnings=APIHelper.SKIP):
        """Initialize a CommissionPayrollPurchaseEvent instance."""
        # Initialize members of the class
        if staff_id is not APIHelper.SKIP:
            self.staff_id = staff_id
        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 sale_id is not APIHelper.SKIP:
            self.sale_id = sale_id
        if sale_type is not APIHelper.SKIP:
            self.sale_type = sale_type
        if product_id is not APIHelper.SKIP:
            self.product_id = product_id
        if earnings_details is not APIHelper.SKIP:
            self.earnings_details = earnings_details
        if earnings is not APIHelper.SKIP:
            self.earnings = earnings

    @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
        staff_id =\
            dictionary.get("StaffId")\
            if dictionary.get("StaffId")\
                else APIHelper.SKIP
        sale_date_time = APIHelper.RFC3339DateTime.from_value(
            dictionary.get("SaleDateTime")).datetime\
            if dictionary.get("SaleDateTime") else APIHelper.SKIP
        sale_id =\
            dictionary.get("SaleId")\
            if dictionary.get("SaleId")\
                else APIHelper.SKIP
        sale_type =\
            dictionary.get("SaleType")\
            if dictionary.get("SaleType")\
                else APIHelper.SKIP
        product_id =\
            dictionary.get("ProductId")\
            if dictionary.get("ProductId")\
                else APIHelper.SKIP
        earnings_details = None
        if dictionary.get("EarningsDetails") is not None:
            earnings_details = [
                CommissionDetail.from_dictionary(x)
                    for x in dictionary.get("EarningsDetails")
            ]
        else:
            earnings_details = APIHelper.SKIP
        earnings =\
            dictionary.get("Earnings")\
            if dictionary.get("Earnings")\
                else APIHelper.SKIP

        # Return an object of this model
        return cls(staff_id,
                   sale_date_time,
                   sale_id,
                   sale_type,
                   product_id,
                   earnings_details,
                   earnings)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _staff_id=(
            self.staff_id
            if hasattr(self, "staff_id")
            else None
        )
        _sale_date_time=(
            self.sale_date_time
            if hasattr(self, "sale_date_time")
            else None
        )
        _sale_id=(
            self.sale_id
            if hasattr(self, "sale_id")
            else None
        )
        _sale_type=(
            self.sale_type
            if hasattr(self, "sale_type")
            else None
        )
        _product_id=(
            self.product_id
            if hasattr(self, "product_id")
            else None
        )
        _earnings_details=(
            self.earnings_details
            if hasattr(self, "earnings_details")
            else None
        )
        _earnings=(
            self.earnings
            if hasattr(self, "earnings")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"staff_id={_staff_id!r}, "
            f"sale_date_time={_sale_date_time!r}, "
            f"sale_id={_sale_id!r}, "
            f"sale_type={_sale_type!r}, "
            f"product_id={_product_id!r}, "
            f"earnings_details={_earnings_details!r}, "
            f"earnings={_earnings!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _staff_id=(
            self.staff_id
            if hasattr(self, "staff_id")
            else None
        )
        _sale_date_time=(
            self.sale_date_time
            if hasattr(self, "sale_date_time")
            else None
        )
        _sale_id=(
            self.sale_id
            if hasattr(self, "sale_id")
            else None
        )
        _sale_type=(
            self.sale_type
            if hasattr(self, "sale_type")
            else None
        )
        _product_id=(
            self.product_id
            if hasattr(self, "product_id")
            else None
        )
        _earnings_details=(
            self.earnings_details
            if hasattr(self, "earnings_details")
            else None
        )
        _earnings=(
            self.earnings
            if hasattr(self, "earnings")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"staff_id={_staff_id!s}, "
            f"sale_date_time={_sale_date_time!s}, "
            f"sale_id={_sale_id!s}, "
            f"sale_type={_sale_type!s}, "
            f"product_id={_product_id!s}, "
            f"earnings_details={_earnings_details!s}, "
            f"earnings={_earnings!s}, "
            f")"
        )
