# DocumentRegistry

[Git Source](https://github.com/EntreDevelopers-Lab-Inc/Mezz-Companies/blob/f7a3e84e3dd5bb33c4bd7f77283983f9e8ba20b2/src/document-registry/DocumentRegistry.sol)

**Inherits:** ContextUpgradeable, HubOwnableUUPSUpgradeable, IDocumentRegistry

**Author:** Daniel Yamagata & Jerry Qi

A registry that keeps track of documents for departments and treasuries

*ContextUpgradeable's \_msgSender() is used instead of msg.sender to support gas relayers in the future if needed Document indices and versions are indexed at zero*

## State Variables

### DocumentRegistryStorageLocation

```solidity
bytes32 private constant DocumentRegistryStorageLocation =
    0x46700f930ad7adfc0a292e81ee80058e1cf74d898e6dd683beb9ef96db973800;
```

## Functions

### \_getDocumentRegistryStorage

```solidity
function _getDocumentRegistryStorage() internal pure returns (DocumentRegistryStorage storage $);
```

### constructor

```solidity
constructor(address _mezzHub) HubOwnableUUPSUpgradeable(_mezzHub);
```

### addDocument

Adds a document to the registry for the caller

*This function is not access controlled: any account can add a document to the registry if desired*

```solidity
function addDocument(string memory documentName, string memory documentUri) external virtual returns (uint256);
```

**Returns**

| Name     | Type      | Description                                                          |
| -------- | --------- | -------------------------------------------------------------------- |
| `<none>` | `uint256` | The document index, which is incremented sequentially for the caller |

### updateDocument

Updates the document associated with 'documentIndex' in the registry for the caller

*This function will revert if the 'documentIndex' is invalid*

```solidity
function updateDocument(uint256 documentIndex, string memory updatedDocumentName, string memory updatedDocumentUri)
    external
    virtual
    returns (uint256);
```

**Parameters**

| Name                  | Type      | Description                         |
| --------------------- | --------- | ----------------------------------- |
| `documentIndex`       | `uint256` | The index of the document to update |
| `updatedDocumentName` | `string`  | The updated name of the document    |
| `updatedDocumentUri`  | `string`  | The updated URI of the document     |

**Returns**

| Name     | Type      | Description                                                                     |
| -------- | --------- | ------------------------------------------------------------------------------- |
| `<none>` | `uint256` | The version of the document, which is incremented sequentially upon each update |

### getLatestDocuments

Returns all of the latest documents associated with an 'owner'

```solidity
function getLatestDocuments(address owner) public view virtual returns (DataTypes.Document[] memory);
```

**Parameters**

| Name    | Type      | Description                |
| ------- | --------- | -------------------------- |
| `owner` | `address` | The owner of the documents |

**Returns**

| Name     | Type                   | Description                                         |
| -------- | ---------------------- | --------------------------------------------------- |
| `<none>` | `DataTypes.Document[]` | A list of documents as a 'DataTypes.Document' array |

### getLatestDocumentByIndex

Returns the latest document given an 'owner' and 'documentIndex'

```solidity
function getLatestDocumentByIndex(address owner, uint256 documentIndex)
    public
    view
    virtual
    returns (DataTypes.Document memory);
```

### getDocumentByVersion

Returns a document given an 'owner', 'documentIndex', and 'documentVersion'

*This function will revert if the document does not exist*

```solidity
function getDocumentByVersion(address owner, uint256 documentIndex, uint256 documentVersion)
    public
    view
    virtual
    returns (DataTypes.Document memory);
```

**Parameters**

| Name              | Type      | Description                 |
| ----------------- | --------- | --------------------------- |
| `owner`           | `address` | The owner of the document   |
| `documentIndex`   | `uint256` | The index of the document   |
| `documentVersion` | `uint256` | The version of the document |

**Returns**

| Name     | Type                 | Description                                   |
| -------- | -------------------- | --------------------------------------------- |
| `<none>` | `DataTypes.Document` | The document as a 'DataTypes.Document' struct |

### \_validateDocumentExistence

*Validates that the document exists, reverts if it does not*

```solidity
function _validateDocumentExistence(address owner, uint256 documentIndex) internal view;
```

## Structs

### DocumentRegistryStorage

```solidity
struct DocumentRegistryStorage {
    mapping(address => mapping(uint256 => DataTypes.VersionedDocuments)) _documentByOwnerByIndex;
    mapping(address => uint256) _nextDocumentIndexByOwner;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mezzanine.xyz/smart-contracts/source-code/documentregistry.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
