/**
 * Data model pour les accessoires
 */
export default class AccessoireDataModel extends foundry.abstract.TypeDataModel {
  static defineSchema() {
    const fields = foundry.data.fields;
    return {
      description: new fields.HTMLField({ initial: "" }),
      rarete: new fields.NumberField({ initial: 0, integer: true }),
      quantite: new fields.NumberField({ initial: 0, integer: true }),
      prix: new fields.NumberField({ initial: 0, integer: true }),
      equipped: new fields.BooleanField({ initial: false }),
      lieu: new fields.NumberField({ initial: 0, integer: true })
    };
  }

  static migrateData(data) {
    for (const key of ["rarete", "quantite", "prix", "lieu"]) {
      if (typeof data[key] === "string") {
        const v = parseInt(data[key]);
        data[key] = Number.isNaN(v) ? 0 : v;
      }
    }
    return data;
  }
}
