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

export default class OathHammerNpcAttack 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 })

    // Flat damage dice pool (no Might)
    schema.damageDice = new fields.NumberField({
      ...requiredInteger, initial: 1, min: 0, max: 20
    })

    // Dice color: white (4+), red (3+), black (2+)
    schema.colorDiceType = new fields.StringField({
      required: true, initial: "white", choices: SYSTEM.DICE_COLOR_TYPES
    })

    // AP (Armor Penetration): penalty imposed on armor rolls
    schema.ap = new fields.NumberField({
      ...requiredInteger, initial: 0, min: 0, max: 16
    })

    return schema
  }

  static LOCALIZATION_PREFIXES = ["OATHHAMMER.NpcAttack"]

  get threshold() {
    return this.colorDiceType === "black" ? 2 : this.colorDiceType === "red" ? 3 : 4
  }

  get colorEmoji() {
    return this.colorDiceType === "black" ? "⬛" : this.colorDiceType === "red" ? "🔴" : "⬜"
  }

  get damageLabel() {
    return `${this.colorEmoji} ${this.damageDice}d (${this.threshold}+)`
  }
}
