import {
  model,
  Model,
  modelAction,
  ModelAutoTypeCheckingMode,
  setGlobalConfig,
  tProp,
  types,
} from 'mobx-keystone';
import { nanoid } from 'nanoid';
import endTimeEnum from '../../constants/endTimeEnum';
import startTimeEnum from '../../constants/startTimeEnum';
/*
const uuidv5 = require("uuid/v5");
const codeTemplate = "20fccdbc-507a-11eb-ae93-0242ac130002";
const pwTemplate = "locked";
*/
setGlobalConfig({
  modelAutoTypeChecking: ModelAutoTypeCheckingMode.AlwaysOn,
});
@model('keystone/Application/TicketModel')
export default class TicketModel extends Model({
  idTemplate: tProp(types.string),
  id: tProp(types.string, () => nanoid(8)),
  title: tProp(types.string, 'empty'),
  subtitle: tProp(types.string, 'subtitle'),
  text: tProp(types.string, 'text'),
  price: tProp(types.number, 10.0),
  credits: tProp(types.number, 1.0),
  startTimeConf: tProp(types.string, startTimeEnum[0].label),
  endTimeConf: tProp(types.string, endTimeEnum[0].label),
  endTimeValidity: tProp(types.number),
  userLevel: tProp(types.number, 0),
  baseAmount: tProp(types.number, 1),
  color: tProp(types.string, 'white'),
}) {
  returnAll() {
    return this;
  }

  @modelAction
  setTitle(title: string) {
    this.title = title;
  }

  @modelAction
  change(
    title: string,
    subtitle: string,
    text: string,
    price: number,
    credits: number,
    startTimeConf: string,
    endTimeConf: string,
    endTimeValidity: Date,
    userLevel: number,
    baseAmount: number,
    color: string,
    idTemplate: string
  ) {
    this.title = title;
    this.subtitle = subtitle;
    this.text = text;
    this.price = price;
    this.credits = credits;
    this.startTimeConf = startTimeConf;
    this.endTimeConf = endTimeConf;
    this.endTimeValidity = +endTimeValidity;
    this.userLevel = userLevel;
    this.baseAmount = baseAmount;
    this.color = color;
    this.idTemplate = idTemplate;
  }
}
