contract Referrers is Ownable {
    using SafeMath for uint256;

    // Referrer bonus in %
    uint public referrerBonusSale;
    uint public referrerBonusWin;
    uint public _referrerId;
    // mapping referrerId to address
    mapping(uint => address) public referrerToAddress;
    // Tickets referals: tokeId => referrerId
    mapping(uint => uint) public ticketToReferrer;
    // Tickets of referrer
    mapping(uint => uint[]) public referrerTickets;
    // mapping address to referrerId
    mapping(address => uint) public addressToReferrer;
    mapping(uint => uint) public totalEarnReferrer;

    constructor() public {
        referrerBonusSale = 8;
        referrerBonusWin = 2;
        _referrerId = 0;
    }

    function _setTicketReferrer(uint _tokenId, uint _referrer) internal {
        require(ticketToReferrer[_tokenId] == 0);
        ticketToReferrer[_tokenId] = _referrer;
        referrerTickets[_referrer].push(_tokenId);
    }

    function registerReferrer() public {
        require(addressToReferrer[msg.sender] == 0);
        _referrerId = _referrerId.add(1);
        addressToReferrer[msg.sender] = _referrerId;
        referrerToAddress[_referrerId] = msg.sender;
    }

    function getReferrerTickets(uint _referrer) public view returns (uint[]) {
        return referrerTickets[_referrer];
    }

    // Admin methods
    function setReferrerBonusWin(uint _amount) public onlyOwner {
        referrerBonusWin = _amount;
    }

    function setReferrerBonusSale(uint _amount) public onlyOwner {
        referrerBonusSale = _amount;
    }
    //End admin methods
}
function setReferrerBonusWin(uint _amount) public onlyOwner {
    referrerBonusWin = _amount;
}

// Admin methods