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

import {Test} from "forge-std/Test.sol";
import {DebtToken} from "../../contracts/vault/tokens/DebtToken.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";

contract DebtTokenTransferableTest is Test {
    DebtToken public token;
    address public vault = address(0x1);
    address public currency = address(0x2);
    address public admin = address(this);
    address public user1 = address(0x10);
    address public user2 = address(0x11);

    function testInitializeFullTransferableAllowsTransfer() public {
        DebtToken impl = new DebtToken();
        bytes memory initData = abi.encodeWithSelector(
            DebtToken.initializeFull.selector,
            "Debt cUSDC (variable)",
            "vdcUSDC",
            vault,
            currency,
            admin,
            uint8(6),
            true // transferable
        );
        ERC1967Proxy proxy = new ERC1967Proxy(address(impl), initData);
        token = DebtToken(address(proxy));
        token.grantRole(keccak256("MINTER_ROLE"), vault);

        assertTrue(token.isTransferable());
        assertEq(token.decimals(), 6);

        vm.prank(vault);
        token.mint(user1, 1000e6);
        vm.prank(user1);
        token.transfer(user2, 500e6);
        assertEq(token.balanceOf(user2), 500e6);
        assertEq(token.balanceOf(user1), 500e6);
    }

    function testInitializeFullNotTransferableRevertsOnTransfer() public {
        DebtToken impl = new DebtToken();
        bytes memory initData = abi.encodeWithSelector(
            DebtToken.initializeFull.selector,
            "Debt cUSDC",
            "vdcUSDC",
            vault,
            currency,
            admin,
            uint8(6),
            false // not transferable
        );
        ERC1967Proxy proxy = new ERC1967Proxy(address(impl), initData);
        token = DebtToken(address(proxy));
        token.grantRole(keccak256("MINTER_ROLE"), vault);

        assertFalse(token.isTransferable());

        vm.prank(vault);
        token.mint(user1, 1000e6);
        vm.prank(user1);
        vm.expectRevert("DebtToken: transfers not allowed");
        token.transfer(user2, 500e6);
    }
}
