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

import typing
import uuid

from hotpocket_backend.apps.accounts.models import Account


class AccountsTestingService:
    EDITABLE_FIELDS = [
        'first_name', 'last_name', 'email',
    ]

    def assert_edited(self, *, pk: uuid.UUID, update: dict, reference: typing.Any):
        account = Account.objects.get(pk=pk)

        for field in self.EDITABLE_FIELDS:
            expected_value = update.get(field, '') or None
            actual_value = getattr(account, field)
            assert actual_value == expected_value, (
                f'Value mismatch: field=`{field}` '
                f'expected_value=`{expected_value}` '
                f'actual_value=`{actual_value}`'
            )

        assert account.updated_at > reference.updated_at

    def assert_password_changed(self,
                                *,
                                pk: uuid.UUID,
                                reference: typing.Any,
                                ):
        account = Account.objects.get(pk=pk)
        assert account.password != reference.password

        assert account.updated_at > reference.updated_at

    def assert_settings_edited(self,
                               *,
                               pk: uuid.UUID,
                               update: dict,
                               reference: typing.Any,
                               ):
        account = Account.objects.get(pk=pk)
        assert account.raw_settings == update

        assert account.updated_at > reference.updated_at
