public function setStructureMetadata($data)
    {
        if ($data === null) {
            $this->structureMetadata = $data;
            $this->terminalStructureMetadata = $data;
        } elseif (is_array($data)) {
            $struct = $this->createStructureMetadata();
            $struct->merge($data);

            $this->structureMetadata = $struct;
            $this->terminalStructureMetadata = $data;
        } elseif ($data instanceof MetadataInterface) {
            $this->structureMetadata = $data;
            $this->terminalStructureMetadata = $data;
        } else {
            throw new InvalidArgumentException(sprintf(
                'Structure [%s] is invalid (must be array or an instance of %s).',
                (is_object($data) ? get_class($data) : gettype($data)),
                StructureMetadata::class
            ));
        }

        $this->isStructureFinalized = false;

        return $this;
    }