import { createCharacteristicField } from "./items/base-item.mjs";
const fields = foundry.data.fields;

export default class CharacterData extends foundry.abstract.TypeDataModel {

    static defineSchema() {
        return {
            name: new fields.StringField({ required: false, blank: false, trim: true }),
            life: new fields.SchemaField({
                value: new fields.NumberField({ required: false, initial: 0, integer: true }),
                max: new fields.NumberField({ required: true, initial: 0, integer: true })
            }),
            personal: new fields.SchemaField({
                title: new fields.StringField({ required: false, blank: true, trim: true }),
                species: new fields.StringField({ required: false, blank: true, trim: true }),
                speciesText: new fields.SchemaField({
                    description: new fields.StringField({ required: false, blank: true, trim: true, nullable: true }),
                    descriptionLong: new fields.HTMLField({ required: false, blank: true, trim: true })
                }),
                age: new fields.StringField({ required: false, blank: true, trim: true }),
                gender: new fields.StringField({ required: false, blank: true, trim: true }),
                pronouns: new fields.StringField({ required: false, blank: true, trim: true }),
                homeworld: new fields.StringField({ required: false, blank: true, trim: true }),
                ucp: new fields.StringField({ required: false, blank: true, trim: true, initial: "" }),
                traits: new fields.ArrayField(
                    new fields.SchemaField({
                        name: new fields.StringField({ required: true, blank: true, trim: true }),
                        description: new fields.StringField({ required: false, blank: true, trim: true })
                    })
                )
            }),
            biography: new fields.HTMLField({ required: false, blank: true, trim: true }),

            characteristics: new fields.SchemaField({
                strength: createCharacteristicField(true, true),
                dexterity: createCharacteristicField(true, true),
                endurance: createCharacteristicField(true, true),
                intellect: createCharacteristicField(true, false),
                education: createCharacteristicField(true, false),
                social: createCharacteristicField(true, false),
                morale: createCharacteristicField(true, false),
                luck: createCharacteristicField(true, false),
                sanity: createCharacteristicField(true, false),
                charm: createCharacteristicField(true, false),
                psionic: createCharacteristicField(true, false),
                other: createCharacteristicField(true, false)
            }),

            health: new fields.SchemaField({
                radiations: new fields.NumberField({ required: false, initial: 0, min: 0, integer: true })
            }),
            study: new fields.SchemaField({
                skill: new fields.StringField({ required: false, blank: true, trim: true, initial: "" }),
                total: new fields.NumberField({ required: false, initial: 0, min: 0, integer: true }),
                completed: new fields.NumberField({ required: false, initial: 0, min: 0, integer: true })
            }),
            finance: new fields.SchemaField({
                pension: new fields.NumberField({ required: true, initial: 0, min: 0, integer: true }),
                credits: new fields.NumberField({ required: true, initial: 0, min: 0, integer: true }),
                cashOnHand: new fields.NumberField({ required: true, initial: 0, min: 0, integer: true }),
                debt: new fields.NumberField({ required: true, initial: 0, min: 0, integer: true }),
                livingCost: new fields.NumberField({ required: true, initial: 0, min: 0, integer: true }),
                monthlyShipPayments: new fields.NumberField({ required: true, initial: 0, min: 0, integer: true }),
                notes: new fields.StringField({ required: false, blank: true, trim: true, initial: "" })
            }),
            containerView: new fields.StringField({ required: false, blank: true, trim: true, initial: "" }),
            containerDropIn: new fields.StringField({ required: false, blank: true, trim: true, initial: "" }),
            notes: new fields.HTMLField({ required: false, blank: true, trim: true }),

            inventory: new fields.SchemaField({
                armor: new fields.NumberField({ required: true, initial: 0, integer: true }),
                weight: new fields.NumberField({ required: true, initial: 0, min: 0, integer: false }),
                encumbrance: new fields.SchemaField({
                    normal: new fields.NumberField({ required: true, initial: 0, min: 0, integer: true }),
                    heavy: new fields.NumberField({ required: true, initial: 0, min: 0, integer: true })
                })
            }),
            states: new fields.SchemaField({
                encumbrance: new fields.BooleanField({ required: false, initial: false }),
                fatigue: new fields.BooleanField({ required: false, initial: false }),
                unconscious: new fields.BooleanField({ required: false, initial: false }),
                surgeryRequired: new fields.BooleanField({ required: false, initial: false })
            }),

            config: new fields.SchemaField({
                psionic: new fields.BooleanField({ required: false, initial: true }),
                initiative: new fields.StringField({ required: false, blank: true, initial: "dexterity" }),
                damages: new fields.SchemaField({
                    rank1: new fields.StringField({ required: false, blank: true, initial: "strength" }),
                    rank2: new fields.StringField({ required: false, blank: true, initial: "dexterity" }),
                    rank3: new fields.StringField({ required: false, blank: true, initial: "endurance" })
                })
            })
        };
    }
}
