# RegistrationController

### Overview

`RegistrationController` is a contract that manages the registration process for Payment ID tokens. The contract allows users to register new Payment IDs and configure their address records across different source types and chains. It enforces registration rules and ensures proper initialization of associated resolver records.

### Key Concepts

| Concept               | Description                                                                                    |
| --------------------- | ---------------------------------------------------------------------------------------------- |
| Name Registration     | Handles the process of registering a unique Payment ID name and creating the associated token. |
| Address Configuration | Sets up initial address records for newly registered Payment IDs.                              |
| Availability Check    | Verifies that a Payment ID name is available before allowing registration.                     |
| Token ID Generation   | Creates a deterministic token ID by hashing the requested name.                                |

### Data Structures

State Variables

| Name        | Type           | Description                                |
| ----------- | -------------- | ------------------------------------------ |
| pidRegistry | IPIDRegistry   | Reference to the PID Registry contract.    |
| resolver    | PublicResolver | Reference to the Public Resolver contract. |
| pid         | IPID           | Reference to the PID token contract.       |

### Functions

Constructor

```solidity
function constructor(
    address _pidRegistry,
    address _resolver,
    address _pid
) public
```

| Input Parameter | Type    | Description                              |
| --------------- | ------- | ---------------------------------------- |
| \_pidRegistry   | address | Address of the PID Registry contract.    |
| \_resolver      | address | Address of the Public Resolver contract. |
| \_pid           | address | Address of the PID token contract.       |

Registration

register

```solidity
function register(
    string calldata name,
    uint256[] calldata sourceTypes,
    uint256[] calldata addrTypes,
    bytes[] calldata destAddress
) external
```

| Input Parameter | Type       | Description                                                       |
| --------------- | ---------- | ----------------------------------------------------------------- |
| name            | string     | The Payment ID name to register.                                  |
| sourceTypes     | uint256\[] | Array of source types (e.g., exchange, wallet).                   |
| addrTypes       | uint256\[] | Array of address types (e.g., blockchain identifiers).            |
| destAddress     | bytes\[]   | Array of destination addresses for each source/address type pair. |

| Reverts                                     | Description                                           |
| ------------------------------------------- | ----------------------------------------------------- |
| RegistrationController\_\_InvalidInput      | Thrown when input arrays have mismatched lengths.     |
| RegistrationController\_\_AlreadyRegistered | Thrown when sender already owns a Payment ID.         |
| RegistrationController\_\_NameAlreadyTaken  | Thrown when the requested name is already registered. |

available

```solidity
function available(uint256 _tokenId) public view returns (bool)
```

| Input Parameter | Type    | Description                         |
| --------------- | ------- | ----------------------------------- |
| \_tokenId       | uint256 | Token ID to check availability for. |

| Returns | Description                                             |
| ------- | ------------------------------------------------------- |
| bool    | `true` if the token ID is available, `false` otherwise. |

Internal Functions

\_setAddresses

```solidity
function _setAddresses(
    uint256 tokenId,
    uint256[] calldata sourceTypes,
    uint256[] calldata addrTypes,
    bytes[] calldata destAddress
) internal
```

| Input Parameter | Type       | Description                                                       |
| --------------- | ---------- | ----------------------------------------------------------------- |
| tokenId         | uint256    | The token ID to set addresses for.                                |
| sourceTypes     | uint256\[] | Array of source types (e.g., exchange, wallet).                   |
| addrTypes       | uint256\[] | Array of address types (e.g., blockchain identifiers).            |
| destAddress     | bytes\[]   | Array of destination addresses for each source/address type pair. |

### Errors

| Error                                       | Description                                           |
| ------------------------------------------- | ----------------------------------------------------- |
| RegistrationController\_\_InvalidInput      | Thrown when input arrays have mismatched lengths.     |
| RegistrationController\_\_AlreadyRegistered | Thrown when sender already owns a Payment ID.         |
| RegistrationController\_\_NameAlreadyTaken  | Thrown when the requested name is already registered. |
