import {
  model,
  Model,
  modelAction,
  ModelAutoTypeCheckingMode,
  setGlobalConfig,
  tProp,
  types,
} from "mobx-keystone";
import { v4 as uuidv4 } from "uuid";

setGlobalConfig({
  modelAutoTypeChecking: ModelAutoTypeCheckingMode.AlwaysOn,
});

@model("keystone/Remote/Counter")
export default class Counter extends Model({
  id: tProp(types.string, () => uuidv4()),
  name: tProp(types.string, ""),
  value: tProp(types.number, 0),
  resetTime: tProp(types.number, -1),
  acs01Id: tProp(types.string, ""),
  siteId: tProp(types.string, ""),
}) {
  @modelAction
  setValue(value: number) {
    console.log(`[Counter] Setting value for ${this.name}: ${this.value} → ${value}`);
    this.value = value;
  }
}
