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

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

@model("keystone/Application/TarifRow")
export default class TarifRow extends Model({
  id: tProp(types.string, () => uuidv4()), // an optional string that will use a random id when not provided
  sequence: tProp(types.number), // a required string
  type: tProp(types.string), // an optional boolean that will default to false
  timeSlot: tProp(types.number),
  repeat: tProp(types.number, 1),
  amount: tProp(types.string),
}) {
  @modelAction
  change(
    sequence: number,
    type: string,
    timeSlot: number,
    repeat: number,
    amount: string
  ) {
    this.sequence = sequence;
    this.type = type;
    this.timeSlot = +timeSlot;
    this.repeat = repeat;
    this.amount = amount;
  }

  get all() {
    return this;
  }

  get allClean() {
    const object = {
      id: this.id,
      sequence: this.sequence,
      type: this.type,
      timeSlot: this.timeSlot,
      repeat: this.repeat,
      amount: this.amount,
      done: false,
    };
    return object;
  }
}
