const {
    SchemaField,
    ObjectField,
    NumberField,
    StringField,
    DocumentIdField,
    ArrayField,
} = foundry.data.fields;

export class GroupDataModel extends foundry.abstract.TypeDataModel {

    static defineSchema() {
        return {
            name: new StringField(),
            inventory: new SchemaField({
                quantity: new NumberField(),
                item: new DocumentIdField(Item)
            }),
            groupId: new DocumentIdField(Actor),
            characters: new ArrayField(
                new DocumentIdField(Actor)
            ),
            settings: new ObjectField(),
        }
    }

    _onCreate(data, options, userId) {
        super._onCreate(data, options, userId);
        Folder.implementation.createDocuments([{name: data.name, type: "Actor"}]).then((
            folder
        ) => {
            this.parent.update({"system.groupId": folder[0]._id});
        })
    }

}
