// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

/**
 * @title  ERC-7683 — Cross-Chain Intents minimal interface
 * @notice Subset of the canonical ERC-7683 specification implemented for AERE
 *         Network. ERC-7683 standardises the "intent" abstraction: a user
 *         signs a declarative order ('I want X on chain Y at price ≤ Z by
 *         deadline T'), a solver fills it, and the origin settler releases
 *         the user's deposited collateral to the solver after on-chain
 *         confirmation.
 *
 * @dev    This file vendors only the structs and function signatures AERE
 *         uses; the full standard includes resolveFor / open variants and
 *         a richer FillInstruction.encodedInstruction format. AERE follows
 *         the canonical types so an Across V3 / Uniswap X solver written
 *         to ERC-7683 will work against AereSpokePool with no changes.
 */

struct Input {
    bytes32 token;       // bytes32-padded address
    uint256 amount;
}

struct Output {
    bytes32 token;
    uint256 amount;
    bytes32 recipient;
    uint256 chainId;
}

/// @notice Order issued from this chain (the origin of the intent).
struct OnchainCrossChainOrder {
    uint32 fillDeadline;
    bytes32 orderDataType;
    bytes orderData;
}

/// @notice Off-chain gas-less order signed by the user; relayed by anyone.
struct GaslessCrossChainOrder {
    address originSettler;
    address user;
    uint256 nonce;
    uint256 originChainId;
    uint32 openDeadline;
    uint32 fillDeadline;
    bytes32 orderDataType;
    bytes orderData;
}

struct FillInstruction {
    uint64 destinationChainId;
    bytes32 destinationSettler;
    bytes originData;
}

struct ResolvedCrossChainOrder {
    address user;
    uint256 originChainId;
    uint32 openDeadline;
    uint32 fillDeadline;
    bytes32 orderId;
    Input[] minReceived;
    Output[] maxSpent;
    Output[] receivers;
    FillInstruction[] fillInstructions;
}

interface IOriginSettler {
    event Open(bytes32 indexed orderId, ResolvedCrossChainOrder resolvedOrder);

    /// @notice Opens an on-chain order. The caller is the user (msg.sender).
    function open(OnchainCrossChainOrder calldata order) external;

    /// @notice Opens a gas-less order signed by user. Permissionless relayer.
    function openFor(
        GaslessCrossChainOrder calldata order,
        bytes calldata signature,
        bytes calldata originFillerData
    ) external;

    /// @notice View resolved-order shape WITHOUT mutating state.
    function resolve(OnchainCrossChainOrder calldata order)
        external
        view
        returns (ResolvedCrossChainOrder memory);

    function resolveFor(GaslessCrossChainOrder calldata order, bytes calldata originFillerData)
        external
        view
        returns (ResolvedCrossChainOrder memory);
}

interface IDestinationSettler {
    /// @notice Solver completes the user's intent on the destination chain.
    /// @param  orderId    Hash uniquely identifying the order.
    /// @param  originData Opaque blob set by the originSettler.
    /// @param  fillerData Optional solver-supplied data.
    function fill(bytes32 orderId, bytes calldata originData, bytes calldata fillerData) external;
}
