
export const XP_TOPIC = {
  XP: { code: 'xp', label: 'xp' },
  XPSORT: { code: 'xpsort', label: 'xp sort' },
  NIVEAU: { code: 'niveau', label: 'Niveau' },
  XPCARAC: { code: 'xpcarac', label: 'xp carac' },
  CARAC: { code: 'carac', label: 'Carac' },
  STRESS: { code: 'stress', label: 'Stress' },
  TRANSFORM: { code: 'xps', label: 'Transformé' },
}

export class ExperienceLog {

  static async add(actor, topic, from, to, raison, manuel = false) {
    if (!actor.isPersonnageJoueur()) {
      return
    }
    if (from == to) {
      return
    }
    const newXpLog = {
      mode: topic?.code ?? topic,
      raison: (manuel ? '(manuel) ' : '') + raison,
      from: from,
      to: to,
      valeur: to - from,
      daterdd: game.system.rdd.calendrier.dateCourante(),
      datereel: game.system.rdd.calendrier.dateReel().replace('T', ' ')
    };
    console.log('ExperienceLog.add', newXpLog)
    const newExperienceLog = (actor.system.experiencelog ?? []).concat([newXpLog]);
    await actor.update({ [`system.experiencelog`]: newExperienceLog }, { noHook: true });
  }

  static labelTopic(topic) {
    const xpt = Object.values(XP_TOPIC).find(it => it.code == topic);
    return xpt?.label ?? xpt?.code ?? topic;
  }
}