// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract DocumentManager {

    struct Document {
        string uri;
        bytes32 documentHash;
        uint256 lastModified;
    }

    mapping(string => Document) private documents;

    event DocumentAdded(string indexed name, string uri, bytes32 documentHash, uint256 timestamp);
    event DocumentRemoved(string indexed name, uint256 timestamp);

    function setDocument(string memory name, string memory uri, bytes32 documentHash) external {
        documents[name] = Document(uri, documentHash, block.timestamp);
        emit DocumentAdded(name, uri, documentHash, block.timestamp);
    }

    function getDocument(string memory name) external view returns (string memory, bytes32, uint256) {
        Document memory doc = documents[name];
        require(doc.lastModified != 0, "Documento nao encontrado");
        return (doc.uri, doc.documentHash, doc.lastModified);
    }

    function removeDocument(string memory name) external {
        require(documents[name].lastModified != 0, "Documento nao encontrado");
        delete documents[name];
        emit DocumentRemoved(name, block.timestamp);
    }
}
