contract KuaiMintableToken is BonusToken {


    uint256 public standardDailyLimit; // maximum amount of token can mint per day
    uint256 public dailyLimitLeft = standardDecimals.mul(1000000); // daily limit left
    uint256 public lastMintTime = 0;

    event Mint(address indexed operator, uint256 value, uint256 mintTime);
    event SetDailyLimit(address indexed operator, uint256 time);

    function KuaiMintableToken(
                    address _owner,
                    uint256 _dailyLimit
                ) public BonusToken() {
        totalSupply_ = 0;
        createTime = block.timestamp;
        lastMintTime = createTime;
        owner = _owner;
        standardDailyLimit = standardDecimals.mul(_dailyLimit);
        dailyLimitLeft = standardDailyLimit;
    }

    // mint mintAmount token
    function mint(uint256 mintAmount) public onlyOperator returns(uint256 _actualRelease) {
        uint256 timestamp = block.timestamp;
        require(!judgeIsReachDailyLimit(mintAmount, timestamp));
        balances[owner] = balances[owner].add(mintAmount);
        totalSupply_ = totalSupply_.add(mintAmount);
        emit Mint(msg.sender, mintAmount, timestamp);
        emit Transfer(address(0), owner, mintAmount);
        return mintAmount;
    }

    function judgeIsReachDailyLimit(uint256 mintAmount, uint256 timestamp) internal returns(bool _exist) {
        bool reached = false;
        if ((timestamp.parseTimestamp().year == lastMintTime.parseTimestamp().year)
            && (timestamp.parseTimestamp().month == lastMintTime.parseTimestamp().month)
            && (timestamp.parseTimestamp().day == lastMintTime.parseTimestamp().day)) {
            if (dailyLimitLeft < mintAmount) {
                reached = true;
            } else {
                dailyLimitLeft = dailyLimitLeft.sub(mintAmount);
                lastMintTime = timestamp;
            }
        } else {
            dailyLimitLeft = standardDailyLimit;
            lastMintTime = timestamp;
            if (dailyLimitLeft < mintAmount) {
                reached = true;
            } else {
                dailyLimitLeft = dailyLimitLeft.sub(mintAmount);
            }
        }
        return reached;
    }


    // set standard daily limit
    function setDailyLimit(uint256 _dailyLimit) public onlyOwner returns(bool){
        standardDailyLimit = _dailyLimit;
        emit SetDailyLimit(msg.sender, block.timestamp);
        return true;
    }
}
function setDailyLimit(uint256 _dailyLimit) public onlyOwner returns(bool){
    standardDailyLimit = _dailyLimit;
    emit SetDailyLimit(msg.sender, block.timestamp);
    return true;
}

// set standard daily limit