from datetime import timedelta

from data_gateway_sdk.protocols.smpm.smpm_ul_device_energy_16b_journal import SmpmUlDeviceEnergy16BJournalData, \
    EventData, SmpmUlDeviceEnergy16bJournalType
from data_gateway_sdk.utils.buf_ref import BufRef


def test_smpm_ul_device_energy_16b_journal() -> None:
    case_serialized = bytes.fromhex("7300cc38000000000000000000000000")  # overflow
    assert SmpmUlDeviceEnergy16BJournalData(days_ago=timedelta(seconds=0.0), valid=False, time_offset=timedelta(seconds=14400.0), journal=(EventData(offset=timedelta(seconds=180.0), code=SmpmUlDeviceEnergy16bJournalType.CHANGE_OFFSET_DAILY_CLOCK), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE))) == SmpmUlDeviceEnergy16BJournalData.parse(BufRef(case_serialized))  # noqa: E501
    assert case_serialized == SmpmUlDeviceEnergy16BJournalData.serialize(SmpmUlDeviceEnergy16BJournalData(days_ago=timedelta(seconds=0.0), valid=False, time_offset=timedelta(seconds=14400.0), journal=(EventData(offset=timedelta(seconds=180.0), code=SmpmUlDeviceEnergy16bJournalType.CHANGE_OFFSET_DAILY_CLOCK), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE))))  # noqa: E501
    case_serialized = bytes.fromhex("7380c038000000000000000000000000")  # overflow
    assert SmpmUlDeviceEnergy16BJournalData(days_ago=timedelta(seconds=0.0), valid=True, time_offset=timedelta(seconds=0.0), journal=(EventData(offset=timedelta(seconds=180.0), code=SmpmUlDeviceEnergy16bJournalType.CHANGE_OFFSET_DAILY_CLOCK), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE))) == SmpmUlDeviceEnergy16BJournalData.parse(BufRef(case_serialized))  # noqa: E501
    assert case_serialized == SmpmUlDeviceEnergy16BJournalData.serialize(SmpmUlDeviceEnergy16BJournalData(days_ago=timedelta(seconds=0.0), journal=(EventData(offset=timedelta(seconds=180.0), code=SmpmUlDeviceEnergy16bJournalType.CHANGE_OFFSET_DAILY_CLOCK), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE)), time_offset=timedelta(seconds=0.0), valid=True))  # noqa: E501
    case_serialized = bytes.fromhex("7380ff38000000000000000000000000")  # overflow
    assert SmpmUlDeviceEnergy16BJournalData(days_ago=timedelta(seconds=0.0), valid=True, time_offset=timedelta(seconds=75600.0), journal=(EventData(offset=timedelta(seconds=180.0), code=SmpmUlDeviceEnergy16bJournalType.CHANGE_OFFSET_DAILY_CLOCK), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE))) == SmpmUlDeviceEnergy16BJournalData.parse(BufRef(case_serialized))  # noqa: E501
    assert case_serialized == SmpmUlDeviceEnergy16BJournalData.serialize(SmpmUlDeviceEnergy16BJournalData(days_ago=timedelta(seconds=0.0), journal=(EventData(offset=timedelta(seconds=180.0), code=SmpmUlDeviceEnergy16bJournalType.CHANGE_OFFSET_DAILY_CLOCK), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE)), time_offset=timedelta(seconds=75600.0), valid=True))  # noqa: E501
    case_serialized = bytes.fromhex("73ffc038000000000000000000000000")  # overflow
    assert SmpmUlDeviceEnergy16BJournalData(days_ago=timedelta(seconds=10972800.0), valid=True, time_offset=timedelta(seconds=0.0), journal=(EventData(offset=timedelta(seconds=180.0), code=SmpmUlDeviceEnergy16bJournalType.CHANGE_OFFSET_DAILY_CLOCK), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE))) == SmpmUlDeviceEnergy16BJournalData.parse(BufRef(case_serialized))  # noqa: E501
    assert case_serialized == SmpmUlDeviceEnergy16BJournalData.serialize(SmpmUlDeviceEnergy16BJournalData(days_ago=timedelta(seconds=10972800.0), journal=(EventData(offset=timedelta(seconds=180.0), code=SmpmUlDeviceEnergy16bJournalType.CHANGE_OFFSET_DAILY_CLOCK), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE)), time_offset=timedelta(seconds=0.0), valid=True))  # noqa: E501
    case_serialized = bytes.fromhex("73ffff38000000000000000000000000")  # overflow
    assert SmpmUlDeviceEnergy16BJournalData(days_ago=timedelta(seconds=10972800.0), valid=True, time_offset=timedelta(seconds=75600.0), journal=(EventData(offset=timedelta(seconds=180.0), code=SmpmUlDeviceEnergy16bJournalType.CHANGE_OFFSET_DAILY_CLOCK), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE))) == SmpmUlDeviceEnergy16BJournalData.parse(BufRef(case_serialized))  # noqa: E501
    assert case_serialized == SmpmUlDeviceEnergy16BJournalData.serialize(SmpmUlDeviceEnergy16BJournalData(days_ago=timedelta(seconds=10972800.0), journal=(EventData(offset=timedelta(seconds=180.0), code=SmpmUlDeviceEnergy16bJournalType.CHANGE_OFFSET_DAILY_CLOCK), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE), EventData(offset=timedelta(seconds=0.0), code=SmpmUlDeviceEnergy16bJournalType.NONE)), time_offset=timedelta(seconds=75600.0), valid=True))  # noqa: E501
