// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";

contract Relation is ReentrancyGuard, Ownable {
    address public GuessWinner;
    address public GuessVictory;
    address public GuessScore;

    struct ShareStruct {
        address superior;
        bool active;
    }
    mapping(address => ShareStruct) private shareData;

    event BonusEvent(address account, address referrer);

    function bind(address _account, address _referrer) external {
        require(
            msg.sender == GuessWinner ||
                msg.sender == GuessVictory ||
                msg.sender == GuessScore,
            "unauthorized"
        );
        require(_account != _referrer, "Can't be yourself");

        shareData[_account].active = true;
        shareData[_account].superior = _referrer;

        emit BonusEvent(_account, _referrer);
    }

    function getUserSuperior(address _user) external view returns (address) {
        return shareData[_user].superior;
    }

    function getUserActive(address _user) external view returns (bool) {
        return shareData[_user].active;
    }

    function setGuessContracts(
        address _guessWinner,
        address _guessVictory,
        address _guessScore
    ) public onlyOwner {
        GuessWinner = _guessWinner;
        GuessVictory = _guessVictory;
        GuessScore = _guessScore;
    }

    constructor() {}
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"address","name":"referrer","type":"address"}],"name":"BonusEvent","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"},{"inputs":[],"name":"GuessScore","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"GuessVictory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"GuessWinner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"},{"internalType":"address","name":"_referrer","type":"address"}],"name":"bind","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"}],"name":"getUserActive","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"}],"name":"getUserSuperior","outputs":[{"internalType":"address","name":"","type":"address"}],"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":[{"internalType":"address","name":"_guessWinner","type":"address"},{"internalType":"address","name":"_guessVictory","type":"address"},{"internalType":"address","name":"_guessScore","type":"address"}],"name":"setGuessContracts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]