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

import {Test} from "forge-std/Test.sol";
import {ReserveSystem} from "../../contracts/reserve/ReserveSystem.sol";
import {ReserveConversionPriceAdapter} from "../../contracts/reserve/ReserveConversionPriceAdapter.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MockERC20Adapter is ERC20 {
    constructor(string memory name, string memory symbol) ERC20(name, symbol) {}
}

contract ReserveConversionPriceAdapterTest is Test {
    ReserveSystem public reserveSystem;
    ReserveConversionPriceAdapter public adapter;
    MockERC20Adapter public weth;
    MockERC20Adapter public usdc;

    address public admin = address(0x1);
    address public priceFeedOperator = address(0x3);

    function setUp() public {
        reserveSystem = new ReserveSystem(admin);
        adapter = new ReserveConversionPriceAdapter(address(reserveSystem));
        weth = new MockERC20Adapter("WETH", "WETH");
        usdc = new MockERC20Adapter("USDC", "USDC");

        vm.startPrank(admin);
        reserveSystem.grantRole(reserveSystem.PRICE_FEED_ROLE(), priceFeedOperator);
        reserveSystem.addSupportedAsset(address(weth), true);
        reserveSystem.addSupportedAsset(address(usdc), true);
        vm.stopPrank();

        vm.startPrank(priceFeedOperator);
        reserveSystem.updatePriceFeed(address(weth), 1732e18, block.timestamp);
        reserveSystem.updatePriceFeed(address(usdc), 1e18, block.timestamp);
        vm.stopPrank();
    }

    function test_adapter_getConversionPrice_quotePerBase() public view {
        uint256 conv = adapter.getConversionPrice(address(weth), address(usdc));
        assertEq(conv, 1732e18);
    }

    function test_adapter_getPrice_delegates() public view {
        (uint256 price,) = adapter.getPrice(address(weth));
        assertEq(price, 1732e18);
    }
}
