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

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

    schema.description = new fields.HTMLField({
      required: false,
      blank: true,
      initial: "",
      textSearch: true,
    })

    // Spell level (1-7+)
    schema.level = new fields.NumberField({
      ...requiredInteger,
      initial: 1,
      min: 1,
      max: 25,
    })

    // Mana cost - base cost of the spell
    schema.manaCost = new fields.NumberField({
      ...requiredInteger,
      required: true,
      initial: 1,
      min: 0,
      label: "Mana Cost"
    })

    // Mana upkeep cost (for sustained spells)
    schema.manaUpkeep = new fields.NumberField({
      ...requiredInteger,
      required: true,
      initial: 0,
      min: 0,
      label: "Mana Upkeep"
    })

    // APC to cast
    schema.apc = new fields.NumberField({
      ...requiredInteger,
      required: true,
      initial: 1,
      min: 0,
      label: "Action Point Cost"
    })

    // Color/Hue of the spell (from the Prism)
    schema.color = new fields.StringField({
      required: true,
      initial: "violet",
      choices: SYSTEM.SPELL_COLORS_CHOICES,
      label: "Spell Color"
    })

    // Color effect description
    schema.colorEffect = new fields.HTMLField({
      required: true,
      initial: "",
      label: "Color Effect"
    })

    // Spell Ascension - can be upcast
    schema.canAscend = new fields.BooleanField({
      required: true,
      initial: true,
      label: "Can Ascend"
    })

    schema.ascensionEffect = new fields.HTMLField({
      required: true,
      initial: "",
      label: "Ascension Effect"
    })

    // Memorized (prepared)
    schema.memorized = new fields.BooleanField({
      required: true,
      initial: false
    })

    // Casting parameters
    schema.castingTime = new fields.StringField({
      required: true,
      initial: "1 action"
    })

    schema.spellRange = new fields.StringField({
      required: true,
      initial: "30ft"
    })

    schema.areaAffected = new fields.StringField({
      required: true,
      initial: "Single target"
    })

    schema.duration = new fields.StringField({
      required: true,
      initial: "Instantaneous"
    })

    schema.savingThrow = new fields.StringField({
      required: true,
      initial: ""
    })

    // Keywords (text field with comma-separated values)
    schema.keywords = new fields.StringField({
      required: true,
      initial: "",
      label: "Keywords"
    })

    // Prism RPG: Targets
    schema.targets = new fields.StringField({
      required: true,
      initial: "Single enemy",
      label: "Targets"
    })

    // Prism RPG: Resolve method (Attack, Saving Throw, None)
    schema.resolve = new fields.StringField({
      required: true,
      initial: "Attack",
      label: "Resolve"
    })

    return schema
  }

  /** @override */
  static LOCALIZATION_PREFIXES = ["PRISMRPG.Spell"]
}
