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

export default class OathHammerSettlement 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: false, textSearch: true })

    schema.archetype = new fields.StringField({
      required: true,
      nullable: false,
      initial: "free-city",
      choices: SYSTEM.SETTLEMENT_ARCHETYPES
    })

    schema.territory  = new fields.StringField({ required: true, nullable: false, initial: "" })
    schema.founded    = new fields.StringField({ required: true, nullable: false, initial: "" })
    schema.population = new fields.StringField({ required: true, nullable: false, initial: "" })

    schema.renown = new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })

    schema.currency = new fields.SchemaField({
      gold:   new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
      silver: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
      copper: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
    })

    schema.garrison   = new fields.StringField({ required: true, nullable: false, initial: "" })
    schema.underSiege = new fields.BooleanField({ required: true, initial: false })
    schema.isCapital  = new fields.BooleanField({ required: true, initial: false })
    schema.taxNotes   = new fields.StringField({ required: true, nullable: false, initial: "" })

    // Linked regiment actor IDs
    schema.garrisonRefs = new fields.ArrayField(
      new fields.StringField({ required: true, nullable: false, blank: false })
    )

    return schema
  }

  static LOCALIZATION_PREFIXES = ["OATHHAMMER.Settlement"]
}
