# Path: mollie/api/objects/chargeback.py
# class Chargeback(ObjectBase):
#     @classmethod
#     def get_resource_class(cls, client):
#         from ..resources.chargebacks import Chargebacks
# 
#         return Chargebacks(client)
# 
#     @property
#     def id(self):
#         return self._get_property("id")
# 
#     @property
#     def amount(self):
#         return self._get_property("amount")
# 
#     @property
#     def settlement_amount(self):
#         return self._get_property("settlementAmount")
# 
#     @property
#     def created_at(self):
#         return self._get_property("createdAt")
# 
#     @property
#     def reason(self):
#         return self._get_property("reason")
# 
#     @property
#     def reversed_at(self):
#         return self._get_property("reversedAt")
# 
#     @property
#     def payment_id(self):
#         return self._get_property("paymentId")
# 
#     @property
#     def payment(self):
#         """Return the Payment object related to this chargeback."""
#         # TODO Use the embedded payment data, if available.
#         return self.client.payments.get(self.payment_id)
# 
#     @property
#     def settlement(self):
#         """Return the Settlement object related to this chargeback, if available."""
#         url = self._get_link("settlement")
#         if not url:
#             return None
# 
#         match = re.search(r"settlements/(stl_[a-zA-Z0-9]+)$", url)
#         if not match:
#             # This should never happen
#             raise DataConsistencyError("Unable to extract the settlementId from settlement URL.")  # pragma: no cover
# 
#         settlement_id = match.group(1)
#         return self.client.settlements.get(settlement_id)
# 
# Path: tests/utils.py
# def assert_list_object(obj, object_type, count=None):
#     """Assert that a List object is correctly working, and has sane contents."""
#     assert isinstance(obj, ObjectList), f"Object {obj} is not a ObjectList instance."
#     assert isinstance(obj.count, int), "ObjectList count is not an integer."
#     if count is not None:
#         assert obj.count == count, "ObjectList does not contain the expected number of items."
#     else:
#         assert obj.count > 0, "ObjectList has no items."
# 
#     # verify items in list
#     items = []
#     for item in obj:
#         assert isinstance(item, object_type)
#         assert item.id is not None
#         items.append(item.id)
# 
#     assert len(items) == obj.count, "Items in ObjectList don't match list count."
#     assert len(set(items)) == obj.count, "Not all object ids in the ObjectList are unique."


from mollie.api.objects.chargeback import Chargeback
from .utils import assert_list_object


PAYMENT_ID = "tr_7UhSN1zuXS"
SETTLEMENT_ID = "stl_jDk30akdN"
CHARGEBACK_ID = "chb_n9z0tp"


def test_get_settlement_chargebacks_by_chargeback_id(oauth_client, response):
    """Get chargebacks relevant to settlement by settlement id."""
    response.get(f"https://api.mollie.com/v2/settlements/{SETTLEMENT_ID}/chargebacks", "chargebacks_list")

    chargebacks = oauth_client.settlement_chargebacks.with_parent_id(SETTLEMENT_ID).list()
    assert_list_object(chargebacks, Chargeback)


def test_list_settlement_chargebacks_by_settlement_object(oauth_client, response):
    """Get a list of chargebacks relevant to settlement object."""
    response.get(f"https://api.mollie.com/v2/settlements/{SETTLEMENT_ID}/chargebacks", "chargebacks_list")
    response.get(f"https://api.mollie.com/v2/settlements/{SETTLEMENT_ID}", "settlement_single")

    settlement = oauth_client.settlements.get(SETTLEMENT_ID)
    chargebacks = oauth_client.settlement_chargebacks.on(settlement).list()

# Path: mollie/api/objects/chargeback.py
# class Chargeback(ObjectBase):
#     @classmethod
#     def get_resource_class(cls, client):
#         from ..resources.chargebacks import Chargebacks
# 
#         return Chargebacks(client)
# 
#     @property
#     def id(self):
#         return self._get_property("id")
# 
#     @property
#     def amount(self):
#         return self._get_property("amount")
# 
#     @property
#     def settlement_amount(self):
#         return self._get_property("settlementAmount")
# 
#     @property
#     def created_at(self):
#         return self._get_property("createdAt")
# 
#     @property
#     def reason(self):
#         return self._get_property("reason")
# 
#     @property
#     def reversed_at(self):
#         return self._get_property("reversedAt")
# 
#     @property
#     def payment_id(self):
#         return self._get_property("paymentId")
# 
#     @property
#     def payment(self):
#         """Return the Payment object related to this chargeback."""
#         # TODO Use the embedded payment data, if available.
#         return self.client.payments.get(self.payment_id)
# 
#     @property
#     def settlement(self):
#         """Return the Settlement object related to this chargeback, if available."""
#         url = self._get_link("settlement")
#         if not url:
#             return None
# 
#         match = re.search(r"settlements/(stl_[a-zA-Z0-9]+)$", url)
#         if not match:
#             # This should never happen
#             raise DataConsistencyError("Unable to extract the settlementId from settlement URL.")  # pragma: no cover
# 
#         settlement_id = match.group(1)
#         return self.client.settlements.get(settlement_id)
# 
# Path: tests/utils.py
# def assert_list_object(obj, object_type, count=None):
#     """Assert that a List object is correctly working, and has sane contents."""
#     assert isinstance(obj, ObjectList), f"Object {obj} is not a ObjectList instance."
#     assert isinstance(obj.count, int), "ObjectList count is not an integer."
#     if count is not None:
#         assert obj.count == count, "ObjectList does not contain the expected number of items."
#     else:
#         assert obj.count > 0, "ObjectList has no items."
# 
#     # verify items in list
#     items = []
#     for item in obj:
#         assert isinstance(item, object_type)
#         assert item.id is not None
#         items.append(item.id)
# 
#     assert len(items) == obj.count, "Items in ObjectList don't match list count."
#     assert len(set(items)) == obj.count, "Not all object ids in the ObjectList are unique."


# Path: tests/test_settlement_chargebacks.py
from mollie.api.objects.chargeback import Chargeback
from .utils import assert_list_object



PAYMENT_ID = "tr_7UhSN1zuXS"
SETTLEMENT_ID = "stl_jDk30akdN"
CHARGEBACK_ID = "chb_n9z0tp"


def test_get_settlement_chargebacks_by_chargeback_id(oauth_client, response):
    """Get chargebacks relevant to settlement by settlement id."""
    response.get(f"https://api.mollie.com/v2/settlements/{SETTLEMENT_ID}/chargebacks", "chargebacks_list")

    chargebacks = oauth_client.settlement_chargebacks.with_parent_id(SETTLEMENT_ID).list()
    assert_list_object(chargebacks, Chargeback)


def test_list_settlement_chargebacks_by_settlement_object(oauth_client, response):
    """Get a list of chargebacks relevant to settlement object."""
    response.get(f"https://api.mollie.com/v2/settlements/{SETTLEMENT_ID}/chargebacks", "chargebacks_list")
    response.get(f"https://api.mollie.com/v2/settlements/{SETTLEMENT_ID}", "settlement_single")

    settlement = oauth_client.settlements.get(SETTLEMENT_ID)
    chargebacks = oauth_client.settlement_chargebacks.on(settlement).list()

    assert_list_object(chargebacks, Chargeback)