// File: contracts/Contract.sol



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

contract Splitter {
    address public owner;
    address public relayAddress;
    address public mixerFeeAddress;
    bytes32 private backupHash;
    uint256 public feeRatio; // Stored as an integer, e.g., 93 represents 0.93

    constructor(address _relayAddress, address _mixerFeeAddress, bytes32 _backupHash) {
        require(_relayAddress != address(0) && _mixerFeeAddress != address(0), "Invalid addresses");
        require(_backupHash != bytes32(0), "Invalid backup hash");

        owner = msg.sender;
        relayAddress = _relayAddress;
        mixerFeeAddress = _mixerFeeAddress;
        backupHash = _backupHash;
        feeRatio = 93; // Default fee ratio set to 0.93 (93/100)
    }

    modifier onlyOwner() {
        require(msg.sender == owner, "Only the contract owner can call this function");
        _;
    }

    function split() public payable {
        require(msg.value > 0, "No value sent");

        uint256 totalAmount = msg.value;
        uint256 splitAmount = (totalAmount * feeRatio) / 100;

        // Calculate the split amounts based on the 93:7 ratio
        // uint256 amount1 = (splitAmount * 93) / 100;
        // uint256 amount2 = splitAmount - amount1;

        // Send the split amounts to the two addresses
        payable(relayAddress).transfer(splitAmount);

        // Send the fee amount to the contract owner
        // payable(owner).transfer(feeAmount);
    }

    function updateAddresses(address _relayAddress, address _mixerFeeAddress) external onlyOwner {
        require(_relayAddress != address(0) && _mixerFeeAddress != address(0), "Invalid addresses");
        relayAddress = _relayAddress;
        mixerFeeAddress = _mixerFeeAddress;
    }

    function updateBackupHash(bytes32 _newBackupHash) external onlyOwner {
        require(_newBackupHash != bytes32(0), "Invalid backup hash");
        backupHash = _newBackupHash;
    }

    function updateFeeRatio(uint256 _newFeeRatio) external onlyOwner {
        require(_newFeeRatio > 0, "Fee ratio must be greater than 0");
        feeRatio = _newFeeRatio;
    }

    function withdrawFunds() external onlyOwner {
        uint256 contractBalance = address(this).balance;
        require(contractBalance > 0, "No balance to withdraw");
        payable(owner).transfer(contractBalance);
    }

    function becomeOwner(bytes32 _providedHash) external {
        require(keccak256(abi.encodePacked(_providedHash)) == backupHash, "Incorrect backup hash");
        owner = msg.sender;
    }

    receive() external payable {
        split();
    }
}