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

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

@model('keystone/Remote/Acs01/Passage')
export default class Passage extends Model({
  id: tProp(types.string),
  name: tProp(types.string),
  zone_1: tProp(
    types.object(() => ({
      id: types.string,
      name: types.string,
      max_users: types.number,
      population: types.number,
      population_offset: types.number,
    }))
  ),
  zone_2: tProp(
    types.object(() => ({
      id: types.string,
      name: types.string,
      max_users: types.number,
      population: types.number,
      population_offset: types.number,
    }))
  ),
  direction: tProp(types.number),
  type: tProp(types.number),
  activated: tProp(types.boolean),
  apb_active: tProp(types.boolean),
  state: tProp(types.number),
  obstacle_state: tProp(types.boolean),
  out_pulse: tProp(
    types.object(() => ({
      installed: types.boolean,
      moduleid: types.string,
      io: types.number,
      pulse_time: types.number,
    }))
  ),
  out_open: tProp(
    types.object(() => ({
      installed: types.boolean,
      moduleid: types.string,
      io: types.number,
      pulse_time: types.number,
    }))
  ),
  out_stop: tProp(
    types.object(() => ({
      installed: types.boolean,
      moduleid: types.string,
      io: types.number,
      pulse_time: types.number,
    }))
  ),
  out_close: tProp(
    types.object(() => ({
      installed: types.boolean,
      moduleid: types.string,
      io: types.number,
      pulse_time: types.number,
    }))
  ),
  in_opened: tProp(
    types.object(() => ({
      installed: types.boolean,
      moduleid: types.string,
      io: types.number,
    }))
  ),
  in_closed: tProp(
    types.object(() => ({
      installed: types.boolean,
      moduleid: types.string,
      io: types.number,
    }))
  ),
  in_obstacle: tProp(
    types.object(() => ({
      installed: types.boolean,
      moduleid: types.string,
      io: types.number,
    }))
  ),
  readers: tProp(
    types.array(
      types.object(() => ({
        id: types.string,
        name: types.string,
        moduleid: types.string,
        passage: types.string,
        zone: types.string,
        type: types.number,
        connection: types.number,
        port: types.number,
        address: types.string,
        baudrate: types.number,
        arm_input: types.string,
        disarm_after_scan: types.boolean,
        scan_allowed_input: types.string,
        last_scan: types.object(() => ({
          time: types.number,
          type: types.number,
          code: types.string,
        })),
      }))
    ),
    () => []
  ),
}) {
  get self() {
    return toJS(this);
  }
}
