import { SYSTEM } from "../config/system.mjs"

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

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

    // Arcane tradition (Elemental / Illusionist / Imperial / Infernal / Runic / Stygian)
    schema.tradition = new fields.StringField({
      required: true, initial: "elemental", choices: SYSTEM.SORCEROUS_TRADITIONS
    })

    // Difficulty Value: the Magic check DV needed to cast this spell
    schema.difficultyValue = new fields.NumberField({ ...requiredInteger, initial: 1, min: 1, max: 10 })

    // Ritual spells take 1 hour to cast; DV is listed with "(Ritual)" in the book
    schema.isRitual = new fields.BooleanField({ initial: false })

    // Magic Missile spells can be intercepted like ranged attacks (p.101)
    schema.isMagicMissile = new fields.BooleanField({ initial: false })

    // Range: "Touch", "Self", "40", "200", "Cone AoE", "Large AoE", etc.
    schema.range = new fields.StringField({ required: true, nullable: false, initial: "" })

    // Duration: "1 hour", "Encounter", "2d3 rounds", etc. Empty = instantaneous.
    schema.duration = new fields.StringField({ required: true, nullable: false, initial: "" })

    // Spell Save: e.g. "DV5 Resilience", "DV3 Acrobatics". Empty = no save.
    schema.spellSave = new fields.StringField({ required: true, nullable: false, initial: "" })

    // Elemental tradition only — sub-element (Air / Earth / Fire / Water / Varies)
    schema.element = new fields.StringField({
      required: false, nullable: true, initial: null, choices: SYSTEM.ELEMENTAL_CHOICES
    })

    // Runic tradition only — what surface/object the rune is inscribed upon
    schema.runeType = new fields.StringField({
      required: false, nullable: true, initial: null, choices: SYSTEM.RUNE_TYPE_CHOICES
    })

    // Runic tradition only — exalted runes activate once then vanish (p.120)
    schema.isExalted = new fields.BooleanField({ initial: false })

    return schema
  }

  static LOCALIZATION_PREFIXES = ["OATHHAMMER.Spell"]
}
