/**
 * Data model pour les personnages joueurs (PC)
 */
export default class EcrymePCDataModel extends foundry.abstract.TypeDataModel {
  static defineSchema() {
    const fields = foundry.data.fields;
    
    // Template biodata
    const biodataSchema = {
      age: new fields.StringField({ initial: "" }),
      size: new fields.StringField({ initial: "" }),
      lieunaissance: new fields.StringField({ initial: "" }),
      nationalite: new fields.StringField({ initial: "" }),
      profession: new fields.StringField({ initial: "" }),
      residence: new fields.StringField({ initial: "" }),
      milieusocial: new fields.StringField({ initial: "" }),
      poids: new fields.StringField({ initial: "" }),
      cheveux: new fields.StringField({ initial: "" }),
      sexe: new fields.StringField({ initial: "" }),
      yeux: new fields.StringField({ initial: "" }),
      enfance: new fields.StringField({ initial: "" }),
      description: new fields.HTMLField({ initial: "" }),
      gmnotes: new fields.HTMLField({ initial: "" })
    };

    // Helper function to create a skill schema (creates new instances each time)
    const createSkillSchema = (keyValue, nameValue, maxValue = 0) => ({
      key: new fields.StringField({ initial: keyValue }),
      name: new fields.StringField({ initial: nameValue }),
      value: new fields.NumberField({ initial: 0, integer: true, min: 0 }),
      max: new fields.NumberField({ initial: maxValue, integer: true, min: 0 })
    });

    // Skills categories
    const physicalSkills = {
      athletics: new fields.SchemaField(createSkillSchema("athletics", "ECRY.ui.athletics")),
      driving: new fields.SchemaField(createSkillSchema("driving", "ECRY.ui.driving")),
      fencing: new fields.SchemaField(createSkillSchema("fencing", "ECRY.ui.fencing")),
      brawling: new fields.SchemaField(createSkillSchema("brawling", "ECRY.ui.brawling")),
      shooting: new fields.SchemaField(createSkillSchema("shooting", "ECRY.ui.shooting"))
    };

    const mentalSkills = {
      anthropomecanology: new fields.SchemaField(createSkillSchema("anthropomecanology", "ECRY.ui.anthropomecanology")),
      ecrymology: new fields.SchemaField(createSkillSchema("ecrymology", "ECRY.ui.ecrymology")),
      traumatology: new fields.SchemaField(createSkillSchema("traumatology", "ECRY.ui.traumatology")),
      traversology: new fields.SchemaField(createSkillSchema("traversology", "ECRY.ui.traversology")),
      urbatechnology: new fields.SchemaField(createSkillSchema("urbatechnology", "ECRY.ui.urbatechnology"))
    };

    const socialSkills = {
      quibbling: new fields.SchemaField(createSkillSchema("quibbling", "ECRY.ui.quibbling")),
      creativity: new fields.SchemaField(createSkillSchema("creativity", "ECRY.ui.creativity")),
      loquacity: new fields.SchemaField(createSkillSchema("loquacity", "ECRY.ui.loquacity")),
      guile: new fields.SchemaField(createSkillSchema("guile", "ECRY.ui.guile")),
      performance: new fields.SchemaField(createSkillSchema("performance", "ECRY.ui.performance"))
    };

    // Helper function to create a cephaly skill schema
    const createCephalySkillSchema = (nameValue) => ({
      name: new fields.StringField({ initial: nameValue }),
      value: new fields.NumberField({ initial: 0, integer: true, min: 0 }),
      max: new fields.NumberField({ initial: 0, integer: true })
    });

    // Cephaly skills
    const cephalySkills = {
      elegy: new fields.SchemaField(createCephalySkillSchema("ECRY.ui.elegy")),
      entelechy: new fields.SchemaField(createCephalySkillSchema("ECRY.ui.entelechy")),
      mekany: new fields.SchemaField(createCephalySkillSchema("ECRY.ui.mekany")),
      psyche: new fields.SchemaField(createCephalySkillSchema("ECRY.ui.psyche")),
      scoria: new fields.SchemaField(createCephalySkillSchema("ECRY.ui.scoria"))
    };

    // Helper function to create an impact schema
    const createImpactSchema = () => ({
      superficial: new fields.NumberField({ initial: 0, integer: true, min: 0 }),
      light: new fields.NumberField({ initial: 0, integer: true, min: 0 }),
      serious: new fields.NumberField({ initial: 0, integer: true, min: 0 }),
      major: new fields.NumberField({ initial: 0, integer: true, min: 0 })
    });

    return {
      // Biodata
      biodata: new fields.SchemaField(biodataSchema),
      
      // Core data
      subactors: new fields.ArrayField(new fields.StringField(), { initial: [] }),
      equipmentfree: new fields.StringField({ initial: "" }),
      
      // Skills
      skills: new fields.SchemaField({
        physical: new fields.SchemaField({
          name: new fields.StringField({ initial: "ECRY.ui.physical" }),
          pnjvalue: new fields.NumberField({ initial: 0, integer: true }),
          skilllist: new fields.SchemaField(physicalSkills)
        }),
        mental: new fields.SchemaField({
          name: new fields.StringField({ initial: "ECRY.ui.mental" }),
          pnjvalue: new fields.NumberField({ initial: 0, integer: true }),
          skilllist: new fields.SchemaField(mentalSkills)
        }),
        social: new fields.SchemaField({
          name: new fields.StringField({ initial: "ECRY.ui.social" }),
          pnjvalue: new fields.NumberField({ initial: 0, integer: true }),
          skilllist: new fields.SchemaField(socialSkills)
        })
      }),
      
      // Impacts
      impacts: new fields.SchemaField({
        physical: new fields.SchemaField(createImpactSchema()),
        mental: new fields.SchemaField(createImpactSchema()),
        social: new fields.SchemaField(createImpactSchema())
      }),
      
      // Cephaly
      cephaly: new fields.SchemaField({
        name: new fields.StringField({ initial: "ECRY.ui.cephaly" }),
        skilllist: new fields.SchemaField(cephalySkills)
      }),
      
      // Internals
      internals: new fields.SchemaField({
        confrontbonus: new fields.NumberField({ initial: 0, integer: true })
      })
    };
  }
}
