contract ChainBowPrivateSale is Pausable {

    using SafeMath for uint256;

    ERC20 public tokenContract;
    address public teamWallet;
    string public leader;
    uint256 public rate = 5000;

    uint256 public totalSupply = 0;

    event Buy(address indexed sender, address indexed recipient, uint256 value, uint256 tokens);

    mapping(address => uint256) public records;

    constructor(address _tokenContract, address _teamWallet, string _leader, uint _rate) public {
        require(_tokenContract != address(0));
        require(_teamWallet != address(0));
        tokenContract = ERC20(_tokenContract);
        teamWallet = _teamWallet;
        leader = _leader;
        rate = _rate;
    }


    function () payable public {
        buy(msg.sender);
    }

    function buy(address recipient) payable public whenNotPaused {
        require(msg.value >= 0.1 ether);

        uint256 tokens =  rate.mul(msg.value);

        tokenContract.transferFrom(teamWallet, msg.sender, tokens);

        records[recipient] = records[recipient].add(tokens);
        totalSupply = totalSupply.add(tokens);

        emit Buy(msg.sender, recipient, msg.value, tokens);

    }


    /**
     * change rate
     */
    function changeRate(uint256 _rate) public onlyOwner {
        rate = _rate;
    }

    /**
     * change team wallet
     */
    function changeTeamWallet(address _teamWallet) public onlyOwner {
        teamWallet = _teamWallet;
    }

    /**
     * withdraw ether
     */
    function withdrawEth() public onlyOwner {
        teamWallet.transfer(address(this).balance);
    }


    /**
     * withdraw foreign tokens
     */
    function withdrawForeignTokens(address _tokenContract) onlyOwner public returns (bool) {
        ERC20Basic token = ERC20Basic(_tokenContract);
        uint256 amount = token.balanceOf(address(this));
        return token.transfer(owner, amount);
    }

}
/**
 * @title ERC20 Private Token Generation Program
 */
function changeRate(uint256 _rate) public onlyOwner {
    rate = _rate;
}

/**
 * change rate
 */