import SR6BaseActorData from '../base-actor-data.mjs';
import { attributesSchema, monitorsSchema, initiativeSchema, skillsSchema } from '../schema-helpers.mjs';

/**
 * Base DataModel for Player and NPC actors.
 * Field names match template.json exactly.
 * TODO: migrate nested structures to SR6AttributeField / SR6SkillField per sprite actor pattern.
 */
export default class SR6HumanoidActorData extends SR6BaseActorData {
    static defineSchema() {
        const fields = foundry.data.fields;
        const modOnly = () => new fields.SchemaField({ mod: new fields.NumberField({ initial: 0 }) });

        return {
            ...super.defineSchema(),
            attributes: attributesSchema(),
            type:       new fields.StringField({ initial: "mundane" }),
            gender:     new fields.StringField({ initial: "" }),
            metatype:   new fields.StringField({ initial: "human" }),
            mortype:    new fields.StringField({ initial: "mundane" }),
            matrixIni:  new fields.StringField({ initial: "vrcold" }),
            ...monitorsSchema(),
            derived: new fields.SchemaField({
                composure:         modOnly(),
                judge_intentions:  modOnly(),
                memory:            modOnly(),
                lift_carry:        modOnly(),
                matrix_perception: modOnly()
            }),
            defenserating: new fields.SchemaField({
                physical: modOnly(),
                matrix:   modOnly(),
                vehicle:  modOnly(),
                astral:   modOnly(),
                social:   modOnly()
            }),
            attackrating: new fields.SchemaField({
                physical: modOnly(),
                astral:   modOnly(),
                matrix:   modOnly(),
                vehicle:  modOnly(),
                social:   modOnly()
            }),
            defensepool: new fields.SchemaField({
                physical:        modOnly(),
                astral:          modOnly(),
                spells_direct:   modOnly(),
                spells_indirect: modOnly(),
                spells_other:    modOnly(),
                vehicle:         modOnly(),
                toxin:           modOnly(),
                damage_physical: modOnly(),
                damage_astral:   modOnly()
            }),
            initiative: initiativeSchema(),
            walk:    new fields.NumberField({ initial: 5 }),
            sprint:  new fields.NumberField({ initial: 10 }),
            perHit:  new fields.NumberField({ initial: 1 }),
            skills:  skillsSchema(),
            tradition: new fields.SchemaField({
                genesisID: new fields.StringField({ initial: "" }),
                name:      new fields.StringField({ initial: "" }),
                attribute: new fields.StringField({ initial: "log" })
            }),
            persona: new fields.SchemaField({
                device: new fields.SchemaField({
                    mod: new fields.SchemaField({
                        a: new fields.NumberField({ initial: 0 }),
                        s: new fields.NumberField({ initial: 0 }),
                        d: new fields.NumberField({ initial: 0 }),
                        f: new fields.NumberField({ initial: 0 })
                    })
                }),
                living: new fields.SchemaField({
                    mod: new fields.SchemaField({
                        a: new fields.NumberField({ initial: 0 }),
                        s: new fields.NumberField({ initial: 0 }),
                        d: new fields.NumberField({ initial: 0 }),
                        f: new fields.NumberField({ initial: 0 })
                    })
                }),
                used: new fields.SchemaField({
                    a: new fields.NumberField({ initial: 0 }),
                    s: new fields.NumberField({ initial: 0 }),
                    d: new fields.NumberField({ initial: 0 }),
                    f: new fields.NumberField({ initial: 0 })
                })
            })
        };
    }
}
