import { SYSTEM } from "../config/system.mjs"
import HamalronTirageTarot from "../documents/tirage-tarot.mjs"

export default class HamalronPNJ extends foundry.abstract.TypeDataModel {

  static defineSchema() {
    const fields = foundry.data.fields
    const requiredInteger = { required: true, nullable: false, integer: true }
    const schema = {}

    schema.enemyType = new fields.StringField({
      required: true,
      initial: "mook",
      choices: Object.fromEntries(Object.entries(SYSTEM.ENEMY_TYPES).map(([key, val]) => [key, val.label]))
    })

    schema.description = new fields.HTMLField({ required: true, textSearch: true })
    schema.notes = new fields.HTMLField({ required: true, textSearch: true })

    return schema
  }

  /** @override */
  static LOCALIZATION_PREFIXES = ["HAMALRON.PNJ"]

  async roll(rollType, rollItem) {
    let roll = await HamalronTirageTarot.prompt({
      rollType,
      rollItem,
      actorId: this.parent.id,
      actorName: this.parent.name,
      actorImage: this.parent.img,
      hasTarget: false,
    })
    if (!roll) return null

    await roll.toMessage({}, { rollMode: roll.options.rollMode })
  }

}
