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

    schema.typeArme = new fields.StringField({required: true, choices: ["melee", "tir"], initial: "melee"});
    schema.allonge = new fields.StringField({required: true, choices: ["courte", "moyenne", "longue", "treslongue"], initial: "courte"});

    schema.specificites = new fields.SchemaField(
      Object.values((game.system.tedeum.config.ARME_SPECIFICITE)).reduce((obj, spec) => {
        obj[spec.id] = new fields.SchemaField({
          hasSpec: new fields.BooleanField({initial: false}),
        });
        return obj;
      }, {})
    );

    schema.portees = new fields.SchemaField(
      Object.values((game.system.tedeum.config.ARME_PORTEES)).reduce((obj, spec) => {
        obj[spec.id] = new fields.SchemaField({
          value: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
        });
        return obj;
      }, {})
    );

    schema.degatsArmure = new fields.SchemaField( {
      sansarmure : new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
      cuir : new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
      plates : new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
      mailles : new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
    });
    
    schema.tempsRecharge = new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 });
    schema.valeurEchecCritique = new fields.NumberField({ ...requiredInteger, initial: 1, min: 1 });

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

    schema.degats = new fields.StringField({ required: false, blank: true, initial: undefined });
    let comp = []
    for (let key of Object.keys(game.system.tedeum.config.armeCompetences)) {
      comp.push(key);
    }
    schema.competence = new fields.StringField({ required: true, choices:comp, initial: "bagarre" });
    schema.competence2 = new fields.StringField({ required: false, choices:comp, initial: "", blank: true });

    schema.prix = new fields.NumberField({ ...requiredDouble, initial: 0, min: 0 });
    schema.monnaie = new fields.StringField({ required: true, blank: false, initial: "denier" });
    
    schema.equipe = new fields.BooleanField({initial: false}),
    
    schema.description = new fields.HTMLField({ required: true, blank: true });

    return schema;
  }
}
