import { SYSTEM } from "../config/system.mjs"
import HellbornRoll from "../documents/roll.mjs"

export default class HellbornVehicle extends foundry.abstract.TypeDataModel {
  static defineSchema() {
    const fields = foundry.data.fields
    const requiredInteger = { required: true, nullable: false, integer: true }
    const schema = {}

    schema.agility = new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
    schema.armor = new fields.StringField({ required: true, initial: "" })
    schema.cargo = new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
    schema.crew = new fields.NumberField({ ...requiredInteger, initial: 1, min: 1 })
    schema.force = new fields.NumberField({ ...requiredInteger, initial: 1, min: 1 })
    schema.range = new fields.StringField({ required: true, initial: "1d6" })
    schema.speed = new fields.StringField({ required: true, initial: "1d6" })
    schema.techAge = new fields.StringField({ required: true, initial: "1d6" })
    schema.tonnage = new fields.NumberField({ required: true, initial: 1, min: 0 })
    schema.damages = new fields.StringField({ required: true, initial: "" })

    schema.cost = new fields.NumberField({ required: true, initial: 0, min: 0 })

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

    return schema
  }

  /** @override */
  static LOCALIZATION_PREFIXES = ["HELLBORN.Vehicle"]

  isEncumbered() {
    return false
  }

    async roll(rollType, rollItem) {
      let opponentTarget
      const hasTarget = opponentTarget !== undefined

      let roll = await HellbornRoll.prompt({
        rollType,
        rollItem,
        actorId: this.parent.id,
        actorName: this.parent.name,
        actorImage: this.parent.img,
        isEncumbered: this.isEncumbered(),
        hasTarget,
        target: opponentTarget
      })
      if (!roll) return null

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

}
