// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.23;

/**
 * @title IHypMailbox — minimal Hyperlane Mailbox interface used by AERE
 *        Warp Routes. Subset of the at-hyperlane-xyz/core canonical interface.
 *
 * @dev   We vendor the minimal surface here instead of pulling the full
 *        at-hyperlane-xyz/core dependency tree to keep the AERE contracts
 *        compilation isolated. When Hyperlane registry merge lands, the
 *        deployed Mailbox address gets plugged into our Warp Route
 *        constructors and we conform to this same interface.
 */
interface IHypMailbox {
    /// @notice Dispatch a message to a remote chain.
    /// @param destinationDomain  Hyperlane "domain" (e.g. 1 for Ethereum mainnet, 2800 for AERE).
    /// @param recipientAddress   The address (bytes32-padded) of the recipient on the remote chain.
    /// @param messageBody        Arbitrary application payload.
    /// @return messageId         Hash of the dispatched message.
    function dispatch(
        uint32 destinationDomain,
        bytes32 recipientAddress,
        bytes calldata messageBody
    ) external payable returns (bytes32 messageId);

    /// @notice Quote the IGP (Interchain Gas Paymaster) fee for a dispatch.
    function quoteDispatch(
        uint32 destinationDomain,
        bytes32 recipientAddress,
        bytes calldata messageBody
    ) external view returns (uint256 fee);

    /// @notice The configured local domain id.
    function localDomain() external view returns (uint32);
}

/**
 * @title IHypMessageRecipient — application contract surface invoked by the
 *        Mailbox when a verified message arrives.
 */
interface IHypMessageRecipient {
    /// @notice Called by the Mailbox after the configured ISM has verified
    ///         the message.
    /// @param origin  Hyperlane domain id of the source chain.
    /// @param sender  The bytes32-padded address of the dispatcher on the
    ///                source chain (must match a trusted-router enrolment).
    /// @param body    Arbitrary payload set by the sender.
    function handle(uint32 origin, bytes32 sender, bytes calldata body) external payable;
}

/// @dev bytes32 ↔ address conversion helpers used throughout Warp Route enrollment.
library TypeCasts {
    function addressToBytes32(address a) internal pure returns (bytes32) {
        return bytes32(uint256(uint160(a)));
    }

    function bytes32ToAddress(bytes32 b) internal pure returns (address) {
        return address(uint160(uint256(b)));
    }
}
