"""Peewee migrations -- 184_MAIN.py.

Create the ``state`` table that replaces the legacy ``/atx300/state/dispatch.json``
file. The table holds a single row (singleton, like ``setup``) with auto-number
counters and last-used user input defaults.

Note: rollback is intentionally not implemented for this migration.
"""

import peewee as pw
from peewee_migrate import Migrator


def migrate(migrator: Migrator, database: pw.Database, *, fake: bool = False) -> None:
    @migrator.create_model
    class State(pw.Model):
        id = pw.AutoField()
        order_num_counter = pw.IntegerField(default=0)
        taxdocument_num_counter = pw.IntegerField(default=0)
        pumporder_num_counter = pw.IntegerField(default=0)
        temperature_air_by_user = pw.DoubleField(null=True)
        temperature_concrete_by_user = pw.DoubleField(null=True)
        weather_by_user = pw.IntegerField(null=True)
        without_water_by_user = pw.BooleanField(default=False)

        class Meta:
            table_name = "state"


def rollback(migrator: Migrator, database: pw.Database, *, fake: bool = False) -> None:
    raise NotImplementedError("rollback not supported: the legacy state.json file is deleted after data is migrated into the state table")
