let summon = args[0].summon;
let duplicates = args[0].duplicates;
let assignedActor = args[0].assignedActor;

let data = {
    actor: {},
    token: {},
    embedded: {
        ActiveEffect: {
            "override": {
                icon: assignedActor.data.img,
                label: `${assignedActor.data.name} Override`,
                changes: []
            }
        },
        Item: {}
    }
};

const name = `${assignedActor.data.token.name} (${summon.data.token.name})`;

const actorElements = ['wildcard', 'bennies', 'fatigue', 'wounds'];
const keptAttributes = ['smarts', 'spirit']

for (const elem of actorElements) {
   data.actor[`data.${elem}`] = assignedActor.data.data[elem];
}

data.actor['name'] = name;
data.token['name'] = name;

for (const attr of keptAttributes) {
    let attrData = assignedActor.data.data.attributes[attr];
    data.embedded.ActiveEffect.override.changes.push({
        key: `data.attributes.${attr}.die.sides`,
        value: assignedActor.data.data.attributes[attr].die.sides,
        mode: foundry.CONST.ACTIVE_EFFECT_MODES.OVERRIDE
    });
    data.embedded.ActiveEffect.override.changes.push({
        key: `data.attributes.${attr}.die.modifier`,
        value: assignedActor.data.data.attributes[attr].die.modifier,
        mode: foundry.CONST.ACTIVE_EFFECT_MODES.OVERRIDE
    });
    let skills = assignedActor.items.filter(
        i => i.type === 'skill' && i.data.data.attribute === attr);
    for(const skill of skills) {
        data.embedded.ActiveEffect.override.changes.push({
            "key": `@Skill{${skill.name}}[data.die.sides]`,
            "value": skill.data.data.die.sides,
            "mode": foundry.CONST.ACTIVE_EFFECT_MODES.OVERRIDE
        });
        data.embedded.ActiveEffect.override.changes.push({
            "key": `@Skill{${skill.name}}[data.die.modifier]`,
            "value": skill.data.data.die.modifier,
            "mode": foundry.CONST.ACTIVE_EFFECT_MODES.OVERRIDE
        });
    }
}
const otherItems = assignedActor.items.filter(
    i => i.type === 'edge' || i.type === 'hindrance')
for(const item of otherItems) {
    data.embedded['Item'][item.name] = item.data;
}

return data;