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

export default class OathHammerNPC 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: true, textSearch: true })
    schema.notes = new fields.HTMLField({ required: true, textSearch: true })

    // NPC (humanoid, needs light) vs Creature (monster, darkvision)
    schema.subtype = new fields.StringField({
      required: true, initial: "creature", choices: SYSTEM.NPC_SUBTYPES
    })

    schema.grit = new fields.SchemaField({
      value: new fields.NumberField({ ...requiredInteger, initial: 2, min: 0 }),
      max: new fields.NumberField({ ...requiredInteger, initial: 2, min: 0 })
    })

    // Armor dice pool (value + color)
    schema.armorDice = new fields.SchemaField({
      value: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0, max: 20 }),
      colorDiceType: new fields.StringField({ required: true, initial: "white", choices: SYSTEM.DICE_COLOR_TYPES })
    })

    schema.defense = new fields.SchemaField({
      value: new fields.NumberField({ ...requiredInteger, initial: 10, min: 0 }),
      colorDiceType: new fields.StringField({ required: true, initial: "white", choices: SYSTEM.DICE_COLOR_TYPES })
    })

    schema.movement = new fields.SchemaField({
      base: new fields.NumberField({ ...requiredInteger, initial: 30, min: 0 })
    })

    schema.attackBonus      = new fields.NumberField({ ...requiredInteger, initial: 0 })
    schema.damageBonus      = new fields.NumberField({ ...requiredInteger, initial: 0 })
    schema.initiativeBonus  = new fields.NumberField({ ...requiredInteger, initial: 0 })
    schema.challengeRating  = new fields.StringField({ required: true, nullable: false, initial: "1" })

    return schema
  }

  static LOCALIZATION_PREFIXES = ["OATHHAMMER.NPC"]

  prepareDerivedData() {
    super.prepareDerivedData()
  }
}
