import { TEMPLATE_DESCRIPTION, TEMPLATE_INVENTAIRE, TEMPLATE_ENCHANTABLE, TEMPLATE_TEMPOREL } from "../common/_module.mjs";
import { INTEGER, STRING } from "../common/field-types.mjs";

const fields = foundry.data.fields;

export default class RdDModelPotion extends foundry.abstract.TypeDataModel {
  static defineSchema() {
    return Object.assign({},
      TEMPLATE_DESCRIPTION.fields(),
      TEMPLATE_INVENTAIRE.fields(),
      TEMPLATE_ENCHANTABLE.fields(),
      TEMPLATE_TEMPOREL.fields(),
      {
        rarete: new fields.StringField({ label: "Rareté", initial: "", ...STRING }),
        categorie: new fields.StringField({ label: "Catégorie", initial: "", ...STRING }),
        etat: new fields.StringField({ label: "État", initial: "", ...STRING }),
        herbe: new fields.StringField({ label: "Herbe", initial: "", ...STRING }),
        herbebrins: new fields.NumberField({ label: "Brins", initial: 0, ...INTEGER }),
        herbebonus: new fields.NumberField({ label: "Bonus herbe", initial: 0, ...INTEGER }),
        reposalchimique: new fields.BooleanField({ label: "Repos alchimique", initial: false }),
        puissance: new fields.NumberField({ label: "Puissance", initial: 0, ...INTEGER }),
      }
    )
  }

  prepareDerivedData() {
    if (this.magique) {
      this.puissance = this.herbebonus * this.pr
    } else {
      this.puissance = 0
    }
  }
}
