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

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

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

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

    schema.armorDice = new fields.SchemaField({
      value:         new fields.NumberField({ ...requiredInteger, initial: 1, min: 0, max: 20 }),
      colorDiceType: new fields.StringField({ required: true, nullable: false, initial: "white", choices: SYSTEM.DICE_COLOR_TYPES }),
    })

    schema.movement        = new fields.NumberField({ ...requiredInteger, initial: 60, min: 0, max: 500 })
    schema.supplyCost      = new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
    schema.recruitmentCost = new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
    schema.mercenary       = new fields.BooleanField({ required: true, initial: false })

    schema.leaderUuid = new fields.StringField({ required: false, nullable: true, initial: null })

    return schema
  }

  static LOCALIZATION_PREFIXES = ["OATHHAMMER.Regiment"]

  get threshold() {
    return { white: 4, red: 3, black: 2 }[this.armorDice.colorDiceType] ?? 4
  }

  get colorEmoji() {
    return { white: "⬜", red: "🔴", black: "⬛" }[this.armorDice.colorDiceType] ?? "⬜"
  }

  get armorLabel() {
    return `${this.colorEmoji} ${this.armorDice.value}d`
  }
}
