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

import {Test} from "forge-std/Test.sol";
import {CcipBridgeAdapter138} from "../../contracts/treasury/CcipBridgeAdapter138.sol";

contract MockWETH9 {
    mapping(address => uint256) public balanceOf;
    function mint(address to, uint256 amount) external {
        balanceOf[to] += amount;
    }
    function transferFrom(address from, address to, uint256 amount) external returns (bool) {
        balanceOf[from] -= amount;
        balanceOf[to] += amount;
        return true;
    }
    function approve(address, uint256) external pure returns (bool) { return true; }
}

contract MockBridge {
    function sendCrossChain(uint64, address, uint256) external payable returns (bytes32) {
        return keccak256("mock");
    }
}

contract CcipBridgeAdapter138Test is Test {
    CcipBridgeAdapter138 public adapter;
    MockWETH9 public weth9;
    MockBridge public bridge;
    address public executor;
    address public receiverMainnet;
    address public admin;

    function setUp() public {
        admin = address(1);
        executor = address(2);
        receiverMainnet = address(3);
        weth9 = new MockWETH9();
        bridge = new MockBridge();
        adapter = new CcipBridgeAdapter138(
            address(weth9),
            address(bridge),
            receiverMainnet,
            admin
        );
        vm.prank(admin);
        adapter.setStrategyExecutor(executor);
    }

    function test_sendWeth9_revert_exportsDisabled() public {
        weth9.mint(executor, 10e18);
        vm.prank(executor);
        vm.expectRevert(CcipBridgeAdapter138.ExportsDisabled.selector);
        adapter.sendWeth9ToMainnet(10e18, 0, block.timestamp + 3600);
    }

    function test_sendWeth9_revert_onlyExecutor() public {
        vm.prank(admin);
        adapter.setExportsEnabled(true);
        weth9.mint(admin, 10e18);
        vm.prank(admin);
        vm.expectRevert(CcipBridgeAdapter138.OnlyExecutor.selector);
        adapter.sendWeth9ToMainnet(10e18, 0, block.timestamp + 3600);
    }

    function test_sendWeth9_success() public {
        vm.prank(admin);
        adapter.setExportsEnabled(true);
        weth9.mint(executor, 10e18);
        vm.prank(executor);
        bytes32 id = adapter.sendWeth9ToMainnet{value: 0}(10e18, 0, block.timestamp + 3600);
        assertEq(id, keccak256("mock"));
    }
}
