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 })

    const attributeField = () => new fields.SchemaField({
      rank: new fields.NumberField({ ...requiredInteger, initial: 1, min: 1, max: 4 })
    })
    schema.attributes = new fields.SchemaField({
      might: attributeField(),
      toughness: attributeField(),
      agility: attributeField(),
      willpower: attributeField(),
      intelligence: attributeField(),
      fate: attributeField()
    })

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

    schema.defense = new fields.SchemaField({
      value: new fields.NumberField({ ...requiredInteger, initial: 10, min: 0 })
    })

    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()
    this.grit.max = this.attributes.might.rank + this.attributes.toughness.rank
  }
}
