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

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

@model('keystone/Application/Template')
export default class Template extends Model({
  id: tProp(types.string, () => uuidv4()), // an optional string that will use a random id when not provided
  name: tProp(types.string), // a required string
  idTemplate: tProp(types.string), // The ACS01 offline key!!
  idTarif: tProp(types.string, ''), // an optional boolean that will default to false
}) {
  @modelAction
  change(name: string, idTemplate: string, idTarif: string) {
    this.name = name;
    this.idTemplate = idTemplate;
    this.idTarif = idTarif;
  }

  @modelAction
  setName(name: string) {
    this.name = name;
  }
}
