/**
 * Donjon & Cie - Systeme FoundryVTT
 *
 * Donjon & Cie est un jeu de role edite par John Doe.
 * Ce systeme FoundryVTT est une implementation independante et n'est pas
 * affilie a John Doe.
 *
 * @author    LeRatierBretonnien
 * @copyright 2025–2026 LeRatierBretonnien
 * @license   CC BY-NC-SA 4.0 – https://creativecommons.org/licenses/by-nc-sa/4.0/
 */

import { DONJON_ET_CIE } from "../donjon-et-cie-config.mjs";

export default class EmployeDataModel extends foundry.abstract.TypeDataModel {
  static defineSchema() {
    const fields = foundry.data.fields;
    const makeCharacteristic = (label, short) => new fields.SchemaField({
      label: new fields.StringField({ initial: label }),
      short: new fields.StringField({ initial: short }),
      value: new fields.NumberField({ initial: 10, integer: true })
    });
    const favorFields = Object.fromEntries(Object.keys(DONJON_ET_CIE.favorDepartments).map((key) => [
      key,
      new fields.SchemaField({
        delta: new fields.NumberField({ initial: 0, integer: true })
      })
    ]));

    return {
      concept: new fields.StringField({ initial: "" }),
      anciennete: new fields.SchemaField({
        rang: new fields.NumberField({ initial: 1, integer: true }),
        libelle: new fields.StringField({ initial: "Nouvel employe" })
      }),
      caracteristiques: new fields.SchemaField({
        force: makeCharacteristic("FORce", "FOR"),
        dexterite: makeCharacteristic("DEXterite", "DEX"),
        constitution: makeCharacteristic("CONstitution", "CON"),
        intelligence: makeCharacteristic("INTelligence", "INT"),
        sagesse: makeCharacteristic("SAGesse", "SAG"),
        charisme: makeCharacteristic("CHArisme", "CHA")
      }),
      sante: new fields.SchemaField({
        dv: new fields.StringField({ initial: "1d6" }),
        pv: new fields.SchemaField({
          value: new fields.NumberField({ initial: 6, integer: true }),
          max: new fields.NumberField({ initial: 6, integer: true })
        })
      }),
      combat: new fields.SchemaField({
        initiativeBonus: new fields.NumberField({ initial: 0, integer: true }),
        attaquesCorpsACorps: new fields.NumberField({ initial: 1, integer: true }),
        attaquesDistance: new fields.NumberField({ initial: 1, integer: true })
      }),
      magie: new fields.SchemaField({
        focus: new fields.SchemaField({
          delta: new fields.NumberField({ initial: 0, integer: true }),
          resultat: new fields.NumberField({ initial: 0, integer: true }),
          sceneId: new fields.StringField({ initial: "" })
        }),
        chaos: new fields.SchemaField({
          delta: new fields.NumberField({ initial: 12, integer: true })
        })
      }),
      profil: new fields.SchemaField({
        objectifPersonnel: new fields.HTMLField({ initial: "" }),
        suspicion: new fields.NumberField({ initial: 0, integer: true }),
        avertissements: new fields.NumberField({ initial: 0, integer: true }),
        missionsReussies: new fields.NumberField({ initial: 0, integer: true })
      }),
      faveurs: new fields.SchemaField(favorFields),
      notes: new fields.HTMLField({ initial: "" }),
      gmnotes: new fields.HTMLField({ initial: "" })
    };
  }
}
