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

    schema.caracteristiques = new fields.SchemaField(
      Object.values(game.system.tedeum.config.caracteristiques).reduce((obj, caracDef) => {
        obj[caracDef.id] = new fields.SchemaField({
            value: new fields.NumberField({ ...requiredInteger, initial: 1, min: 1, max: 12 }),
            experience: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0, max: 10000 }),
        });
        return obj;
      }, {})
    );

    schema.providence = new fields.SchemaField({
      value: new fields.NumberField({ ...requiredInteger, initial: 1, min: 0 }),
    });
    schema.bienveillance = new fields.SchemaField({
      value: new fields.NumberField({ ...requiredInteger, initial: 10, min: 0 }),
    });

    schema.localisation = new fields.SchemaField(
      Object.values(game.system.tedeum.config.LOCALISATION).reduce((obj, loc) => {
        obj[loc.id] = new fields.SchemaField({
          armure: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0, max: 20 }),
          touche:  new fields.NumberField({ ...requiredInteger, initial: 0, min: 0, max: 20 }),
          blessures: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0, max: 20 })          
        });
        return obj;
      }, {})
    );

    schema.fortune = new fields.SchemaField({
      "ecu": new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }), 
      "livres": new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }) ,
      "sous": new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }) ,
      "deniers": new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }) 
    });

    schema.description = new fields.HTMLField({required: true, blank: true});
    schema.connaissances = new fields.HTMLField({required: true, blank: true});
    schema.vetements = new fields.HTMLField({required: true, blank: true});
    //schema.descriptiongraces = new fields.HTMLField({required: true, blank: true});
    schema.genre = new fields.StringField({required: true, choices: ["Homme", "Femme"], initial: "Femme"});
    schema.age = new fields.StringField({ required: false, blank: true, initial: undefined });
    schema.statutocial = new fields.StringField({ required: false, blank: true, initial: undefined });
    schema.chargestitre = new fields.StringField({ required: false, blank: true, initial: undefined });
    schema.charges = new fields.StringField({ required: false, blank: true, initial: undefined });
    schema.religion = new fields.StringField({ required: false, blank: true, initial: undefined });
    schema.lieunaissance = new fields.StringField({ required: false, blank: true, initial: undefined });
    
    return schema;
  }
}
