# -*- coding: utf-8 -*-
from __future__ import annotations

import typing
import uuid

from hotpocket_backend.apps.saves.models import Save
from hotpocket_testing.asserts import assert_datetimes_are_really_close


class SavesTestingService:
    def assert_created(self,
                       *,
                       pk: uuid.UUID,
                       account_uuid: uuid.UUID,
                       url: str,
                       is_netloc_banned: bool,
                       **kwargs,
                       ):
        save = Save.objects.get(pk=pk)
        assert save.account_uuid == account_uuid
        assert save.url == url
        assert save.last_processed_at is None
        assert save.is_netloc_banned == is_netloc_banned

        for field, expected_value in kwargs.items():
            actual_value = getattr(save, field)
            assert actual_value == expected_value, (
                f'Value mismatch: field=`{field}` '
                f'expected_value=`{expected_value}` '
                f'actual_value=`{actual_value}`'
            )

        assert_datetimes_are_really_close(
            save.created_at, save.updated_at,
        )

    def assert_reused(self,
                      pk: uuid.UUID,
                      reference: typing.Any,
                      ):
        save = Save.objects.get(pk=pk)
        assert save.pk == reference.pk
        assert save.account_uuid == reference.account_uuid
        assert save.url == reference.url
        assert save.title == reference.title
        assert save.last_processed_at == reference.last_processed_at
        assert save.is_netloc_banned == reference.is_netloc_banned

        assert save.created_at == reference.created_at
        assert save.updated_at == reference.updated_at
