import { toJS } from 'mobx';
import {
  model,
  Model,
  ModelAutoTypeCheckingMode,
  setGlobalConfig,
  tProp,
  types,
} from 'mobx-keystone';

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

@model('keystone/Remote/Acs01/Reader')
export default class Reader extends Model({
  id: tProp(types.string),
  name: tProp(types.string),
  moduleid: tProp(types.string),
  passage: tProp(types.string),
  zone: tProp(types.string),
  type: tProp(types.number),
  connection: tProp(types.number),
  port: tProp(types.number),
  address: tProp(types.string),
  baudrate: tProp(types.number),
  arm_input: tProp(types.string),
  disarm_after_scan: tProp(types.boolean),
  scan_allowed_input: tProp(types.string),
  last_scan: tProp(
    types.object(() => ({
      time: types.number,
      type: types.number,
      code: types.string,
    }))
  ),
}) {
  get self() {
    return toJS(this);
  }
}
