pragma solidity 0.8.6;




contract Redeem is Ownable {
    using SafeMath for uint;

    uint256 startTime = 1655720662;
    bool private start = true;
    ITerminalV1_1 public terminal;
    ITicketBooth iTicketBooth;


    modifier checkStart() {
        require(start, "pause");
        _;
    }

    constructor(address _terminal,address _iTicketBooth) public{
        terminal = ITerminalV1_1(_terminal);
        iTicketBooth = ITicketBooth(_iTicketBooth);
    }

    function getRedeemAmount(uint256 _amount) public view returns(uint256){
        uint256 ethAmount = _amount.div(1000000);
        if((block.timestamp - startTime) < 604800){
            return ethAmount.mul(5).div(10);
        }
        if((block.timestamp - startTime) < 604800 * 2 && (block.timestamp - startTime) >= 604800 ){
            return ethAmount.mul(7).div(10);
        }
        if((block.timestamp - startTime) < 604800 * 3 && (block.timestamp - startTime) >= 604800 * 2){
            return ethAmount.mul(9).div(10);
        }
    }

    function redeem() public checkStart{
        uint256 amount = iTicketBooth.stakedBalanceOf(msg.sender, 568);
        require(amount > 0 , "Can not redeem");
        terminal.redeem(msg.sender, 568, amount, 0, payable(msg.sender), false);
        uint ethAmount = getRedeemAmount(amount);
        payable(msg.sender).transfer(ethAmount);
    }

    function withdrawMoney() external onlyOwner {
        (bool success, ) = msg.sender.call{value: address(this).balance}("");
        require(success, "Transfer failed.");
    }

    fallback() external payable {}
    
    receive() external payable {}

}
[{"inputs":[{"internalType":"address","name":"_terminal","type":"address"},{"internalType":"address","name":"_iTicketBooth","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"getRedeemAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"redeem","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"terminal","outputs":[{"internalType":"contract ITerminalV1_1","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawMoney","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]