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

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

@model('keystone/Ui/Ui')
export default class Ui extends Model({
  id: tProp(types.string, () => uuidv4()),
  priceToPay: tProp(types.number, -1),
  lostTicketMode: tProp(types.boolean, false),
  viewDetail: tProp(types.boolean, false),
  viewCancel: tProp(types.boolean, false),
  emvPaymentSuccess: tProp(types.boolean, false),
  emvPaymentNotNeccessary: tProp(types.boolean, false).withSetter(),
  emvPaymentId: tProp(types.string, ''),
  emvState: tProp(types.number, 1).withSetter(),
  emvInitState: tProp(types.number, 1).withSetter(),
  creditsOnTicket: tProp(types.number, 0).withSetter(),
  creditsError: tProp(types.boolean, false).withSetter(),
  wantsProofOfPayment: tProp(types.boolean, false).withSetter(),
  title: tProp(types.string, 'Came').withSetter(), // for the emv proof of payment
  itemText: tProp(types.string, 'Betaling van parking ticket').withSetter(), // for the emv proof of payment
  method: tProp(types.string, 'Bancontact').withSetter(), // for the emv proof of payment
  goodBy: tProp(types.string, 'Bedankt en tot ziens').withSetter(), // for the emv proof of payment
  btw: tProp(types.number, 21).withSetter(), // for the emv proof of payment
  manualPayOption: tProp(types.boolean, false).withSetter(), // America, manual pay option
  emvTransactionCancelled: tProp(types.boolean, false),
}) {
  // Reset the global ui values on application reboot
  onAttachedToRootStore = () => {
    this.setPriceToPay(-1);
    this.setLostTicketMode(false);
    this.setViewDetail(false);
    this.setViewCancel(false);
    this.setEmvPaymentSuccess(false);
    this.setEmvPaymentNotNeccessary(false);
    this.setEmvState(1);
    this.setCreditsOnTicket(0);
    this.setCreditsError(false);
    this.setWantsProofOfPayment(false);
    this.setEmvTransactionCancelled(false);
  };

  @modelAction
  setEmvPaymentId(emvPaymentId: string) {
    this.emvPaymentId = emvPaymentId;
  }

  @modelAction
  setEmvPaymentSuccess(emvPaymentSuccess: boolean) {
    this.emvPaymentSuccess = emvPaymentSuccess;
  }

  @modelAction
  setViewCancel(viewCancel: boolean) {
    this.viewCancel = viewCancel;
  }

  @modelAction
  setPriceToPay(priceToPay: number) {
    this.priceToPay = priceToPay;
  }

  @modelAction
  setViewDetail(viewDetail: boolean) {
    this.viewDetail = viewDetail;
  }

  @modelAction
  setLostTicketMode(lostTicketMode: boolean) {
    this.lostTicketMode = lostTicketMode;
  }

  @modelAction
setEmvTransactionCancelled(value: boolean) {
  this.emvTransactionCancelled = value;
}
}
