export class TeDeumEducationSchema 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.etape = new fields.StringField({required: true, initial: "pouponniere"});
    schema.accessible = new fields.SchemaField(
      Object.values((game.system.tedeum.config.origineSociale)).reduce((obj, spec) => {
        obj[spec.id] = new fields.SchemaField({
          isaccessible: new fields.BooleanField({initial: false}),
        });
        return obj;
      }, {})
    );
    schema.caracteristiques = new fields.SchemaField(Array.fromRange(3, 1).reduce((caracs, i) => {
      caracs[`carac${i}`] = new fields.SchemaField({
        caracId: new fields.StringField({ required: true, blank: false, initial: "entregent" })
      });
      return caracs;
    }, {}));
    schema.competences = new fields.SchemaField(Array.fromRange(9, 1).reduce((comps, i) => {
      comps[`comp${i}`] = new fields.SchemaField({
        compName: new fields.StringField({ required: true, blank: true, initial: "" })
      });
      return comps;
    }, {}));
    schema.questionnaire = new fields.SchemaField(Array.fromRange(4, 1).reduce((questions, i) => {
      questions[`question${i}`] = new fields.SchemaField({
        question: new fields.StringField({ required: true, blank: true, initial: "" }),
        reponses: new fields.SchemaField( Array.fromRange(6, 1).reduce((resp, i) => {
          resp[`reponse${i}`] = new fields.SchemaField({
            num: new fields.NumberField({ ...requiredInteger, initial: i, min:i }),
            reponse: new fields.StringField({ required: true, blank: true, initial: "" }),
            compName: new fields.StringField({ required: true, blank: true, initial: "" })
          });
          return resp;
        }, {}))
      });
      return questions;
    }, {}));
    schema.cagnotteMultiplier = new fields.NumberField({ ...requiredDouble, initial: 1.0, min: 0 });
 
    schema.description = new fields.HTMLField({ required: true, blank: true });

    return schema;
  }
}
