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

import {Script, console} from "forge-std/Script.sol";
import {AddressMapper} from "../contracts/utils/AddressMapper.sol";

/**
 * @title DeployAddressMapper
 * @notice Deploy the AddressMapper contract to provide address mapping
 */
contract DeployAddressMapper is Script {
    function run() external {
        uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
        address deployer = vm.addr(deployerPrivateKey);
        
        console.log("Deploying AddressMapper with deployer:", vm.toString(deployer));
        
        vm.startBroadcast(deployerPrivateKey);
        
        AddressMapper mapper = new AddressMapper();
        console.log("AddressMapper deployed at:", vm.toString(address(mapper)));
        
        // Verify mappings
        address weth9Genesis = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
        address weth9Deployed = 0x3304b747E565a97ec8AC220b0B6A1f6ffDB837e6;
        address weth10Genesis = 0xf4BB2e28688e89fCcE3c0580D37d36A7672E8A9F;
        address weth10Deployed = 0x105F8A15b819948a89153505762444Ee9f324684;
        
        address mappedWETH9 = mapper.getDeployedAddress(weth9Genesis);
        address mappedWETH10 = mapper.getDeployedAddress(weth10Genesis);
        
        console.log("\n=== Mapping Verification ===");
        console.log("WETH9 Genesis:", vm.toString(weth9Genesis));
        console.log("WETH9 Mapped:", vm.toString(mappedWETH9));
        console.log("WETH9 Expected:", vm.toString(weth9Deployed));
        require(mappedWETH9 == weth9Deployed, "WETH9 mapping incorrect");
        
        console.log("WETH10 Genesis:", vm.toString(weth10Genesis));
        console.log("WETH10 Mapped:", vm.toString(mappedWETH10));
        console.log("WETH10 Expected:", vm.toString(weth10Deployed));
        require(mappedWETH10 == weth10Deployed, "WETH10 mapping incorrect");
        
        console.log("\nOK: All mappings verified!");
        
        vm.stopBroadcast();
        
        console.log("\n=== Deployment Summary ===");
        console.log("AddressMapper:", vm.toString(address(mapper)));
        console.log("Owner:", vm.toString(mapper.owner()));
    }
}

