import BaseItem from "./baseItem.mjs";

const {ArrayField, BooleanField, NumberField, AnyField, StringField, HTMLField} = foundry.data.fields;

export class ActiveEffectDataModel extends BaseItem {

    static defineSchema() {
        return {
            name: new StringField({required: true}),
            notes: new HTMLField(),
            unique: new BooleanField({initial: false}),
            effects: new AnyField()
        }
    }

    _onCreate(data, options, userId) {
        super._onCreate(data, options, userId);

        if (this.parent.getEmbeddedCollection("ActiveEffect").contents.length === 0) {

            this.parent.createEmbeddedDocuments("ActiveEffect", [{
                name: data.name,
                changes: data.system.effects,
                duration: {},
                icon: this.img,
            }]);

        }
    }

}
