/**
 * Data model for Item items
 */
export default class BoLItemDataModel extends foundry.abstract.TypeDataModel {
  static defineSchema() {
    const fields = foundry.data.fields;
    const requiredInteger = { required: true, nullable: false, integer: true };
    const nullableNumber = { required: false, nullable: true, initial: null };
    
    return {
      // Base fields
      category: new fields.StringField({ initial: "" }),
      subtype: new fields.StringField({ initial: "default" }),
      description: new fields.HTMLField({ initial: "" }),
      properties: new fields.SchemaField({
        // Base flags
        ranged: new fields.BooleanField({ initial: false }),
        melee: new fields.BooleanField({ initial: false }),
        spell: new fields.BooleanField({ initial: false }),
        protection: new fields.BooleanField({ initial: false }),
        weapon: new fields.BooleanField({ initial: false }),
        armor: new fields.BooleanField({ initial: false }),
        helm: new fields.BooleanField({ initial: false }),
        shield: new fields.BooleanField({ initial: false }),
        equipable: new fields.BooleanField({ initial: false }),
        consumable: new fields.BooleanField({ initial: false }),
        magical: new fields.BooleanField({ initial: false }),
        "2H": new fields.BooleanField({ initial: false }),
        reloadable: new fields.BooleanField({ initial: false }),
        bow: new fields.BooleanField({ initial: false }),
        crossbow: new fields.BooleanField({ initial: false }),
        throwing: new fields.BooleanField({ initial: false }),

        // Equipment
        stackable: new fields.BooleanField({ initial: false }),
        stacksize: new fields.NumberField({ ...nullableNumber }),
        slot: new fields.StringField({ initial: "-" }),

        // Weapon flags
        natural: new fields.BooleanField({ initial: false }),
        concealable: new fields.BooleanField({ initial: false }),
        ignoreshield: new fields.BooleanField({ initial: false }),
        attackBonusDice: new fields.BooleanField({ initial: false }),
        attackMalusDice: new fields.BooleanField({ initial: false }),
        onlymodifier: new fields.BooleanField({ initial: false }),
        bashing: new fields.BooleanField({ initial: false }),
        throwable: new fields.BooleanField({ initial: false }),
        damageReroll1: new fields.BooleanField({ initial: false }),

        // Weapon stats
        attackAttribute: new fields.StringField({ initial: "vigor" }),
        attackAptitude: new fields.StringField({ initial: "melee" }),
        attackModifiers: new fields.NumberField({ ...nullableNumber }),
        weaponSize: new fields.StringField({ initial: "unarmed" }),
        damage: new fields.StringField({ initial: "0" }),
        damageAttribute: new fields.StringField({ initial: "" }),
        damageModifiers: new fields.NumberField({ ...nullableNumber }),
        damageMultiplier: new fields.StringField({ initial: "1" }),
        range: new fields.NumberField({ ...nullableNumber }),
        reload: new fields.NumberField({ ...nullableNumber }),

        // Protection
        armorQuality: new fields.StringField({ initial: "" }),
        soak: new fields.SchemaField({
          formula: new fields.StringField({ initial: "" }),
          value: new fields.NumberField({ initial: 0, nullable: true }),
          modifier: new fields.NumberField({ initial: 0, nullable: true }),
        }),
        blocking: new fields.SchemaField({
          malus: new fields.NumberField({ initial: 0, nullable: true }),
          blocking1: new fields.BooleanField({ initial: false }),
          blockingAll: new fields.BooleanField({ initial: false }),
        }),
        modifiers: new fields.SchemaField({
          init: new fields.NumberField({ initial: 0, nullable: true }),
          agility: new fields.NumberField({ initial: 0, nullable: true }),
          powercost: new fields.NumberField({ initial: 0, nullable: true }),
          social: new fields.BooleanField({ initial: false }),
        }),

        // Spell
        circle: new fields.NumberField({ initial: 0, nullable: true }),
        difficulty: new fields.StringField({ initial: "" }),
        ppcost: new fields.NumberField({ initial: 0, nullable: true }),
        duration: new fields.StringField({ initial: "" }),
        nbmandatoryconditions: new fields.NumberField({ initial: 0, nullable: true }),
        mandatoryconditions: new fields.ArrayField(new fields.StringField()),
        optionnalconditions: new fields.ArrayField(new fields.StringField()),

        // Alchemy
        alchemytype: new fields.StringField({ initial: "" }),
        pccost: new fields.NumberField({ initial: 0, nullable: true }),
        pccurrent: new fields.NumberField({ initial: 0, nullable: true }),

        // Vehicle weapon
        isfiredamage: new fields.BooleanField({ initial: false }),
        ishulldamage: new fields.BooleanField({ initial: false }),
        iscrewdamage: new fields.BooleanField({ initial: false }),
        isboarding: new fields.BooleanField({ initial: false }),
        isspur: new fields.BooleanField({ initial: false }),
        isbreakrow: new fields.BooleanField({ initial: false }),
      }),
      
      // Equipment fields
      quantity: new fields.NumberField({ ...requiredInteger, initial: 1 }),
      weight: new fields.NumberField({ initial: 0 }),
      price: new fields.NumberField({ initial: 0 }),
      worn: new fields.BooleanField({ initial: false })
    };
  }

  static LOCALIZATION_PREFIXES = ["BOL.Item"];
}
