import common from '../definitions/common.json';
import rawDefinition from '../definitions/malware.json';
import deepmerge from 'deepmerge';

import {Base} from './Base';

class Malware extends Base  {

    constructor() {
        const definition_extension = {
            "img": "malware.png",
            "prefix": "malware--",
            "active": true,
            "relationships": [
                {"type": "authored-by", "target": "threat-actor"},
                {"type": "authored-by", "target": "intrusion-set"},
                {"type": "targets", "target": "identity"},
                {"type": "beacons-to", "target": "infrastructure"},
                {"type": "exfiltrates-to", "target": "infrastructure"},
                {"type": "communicates-with", "target": "observable", "sub-target": "ipv4-addr"},
                {"type": "communicates-with", "target": "observable", "sub-target": "ipv6-addr"},
                {"type": "communicates-with", "target": "observable", "sub-target": "domain-name"},
                {"type": "communicates-with", "target": "observable", "sub-target": "url"},
                {"type": "compromises", "target": "infrastructure"},
                {"type": "targets", "target": "vulnerability"},
                {"type": "targets", "target": "infrastructure"},
                {"type": "uses", "target": "infrastructure"},
                {"type": "uses", "target": "tool"},
                {"type": "uses", "target": "malware"},
                {"type": "uses", "target": "attack-pattern"},
                {"type": "variant-of", "target": "malware"},
                {"type": "controls", "target": "malware"},
                {"type": "downloads", "target": "malware"},
                {"type": "drops", "target": "malware"},
                {"type": "downloads", "target": "tool"},
                {"type": "drops", "target": "tool"},
                {"type": "downloads", "target": "observable", "sub-target": "file"},
                {"type": "drops", "target": "observable", "sub-target": "file"},
                {"type": "identifies", "target": "observable", "sub-target": "artifact", "x_embed": "sample_refs"},
                {"type": "operates-on", "target": "observable", "sub-target": "software", "x_embed": "operating_system_refs"},
                {"type": "identifies", "target": "artifact", "x_embed": "sample_refs"},
                {"type": "originates-from", "target": "location", "x_exclusive": true},
                {"type": "targets", "target": "location"},
                {"type": "created-by", "target": "identity", "x_exclusive": true, "x_embed": "created_by_ref"}
            ]
        }

        let def = deepmerge(definition_extension, rawDefinition);

        super(common, def);

        // Hoist vocabs onto properties
        this.properties["malware_types"].vocab = this.definitions["malware-type-ov"].enum;
        this.properties["architecture_execution_envs"].vocab = this.definitions["processor-architecture-ov"].enum;
        this.properties["implementation_languages"].vocab = this.definitions["implementation-language-ov"].enum;
        this.properties["capabilities"].vocab = this.definitions["malware-capabilities-ov"].enum;

        this.properties["operating_system_refs"].control = "hidden";
        this.properties["sample_refs"].control = "hidden";
        this.properties["aliases"].control = "csv";
    }
}

const singleton = new Malware();

export default singleton;
