// Contract: BOptions
// Target function: function rewardmultiplier(uint _id, address _staker) public view returns(uint,int)
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.7;

contract BOptions{
    // DAI address 
    IERC20 public DAI = IERC20(0x6B175474E89094C44Da98b954EedeAC495271d0F);
    ETHPriceConsumerV3 public ETHUSD = ETHPriceConsumerV3(0xF92F490703761E21094FbB950F894C1e70e3Cfc1);
    BTCPriceConsumerV3 public BTCUSD = BTCPriceConsumerV3(0xAa5778eDc3DffF92e20Fb0F3746BbcE9A9b2670A);
    DAIPriceConsumerV3 public DAIUSD = DAIPriceConsumerV3(0x3e30b8F8Eb155383d0B3f031958Fb7373A37Ec80);

    event Placebet(address indexed player, bet indexed newoption);
    event SettleOption(address indexed player, bet indexed betinfo,bool wonorlost);

    enum Status {nobet,beton,won,lost}
    enum Instrument {ETH,WBTC}

    struct bet {
        uint id;
        Instrument instrument;
        uint stake;
        int strikeprice;
        uint timestamp;
        uint expiredat;
        uint reward;
        Status betstatus; //enum
        bool longorshort; //true if long 
    }
    
    address public constant owner = 0x0BcDa3524F0BDd07525Ab0Ad88C608ad850a3EA7;
    mapping (address => bet[]) public Accountbets;

    receive() external payable{}

    function withdrawDAI(uint amount) external returns(bool){
        require(msg.sender == owner, "You are not the owner");
        require(amount <= getDAIbalance(), "Not enough DAI balance");
        bool txn = DAI.transfer(payable(msg.sender),amount * 1e18);
        return txn;
    }

    function withdrawETH(uint amount) external  {
        require(msg.sender == owner, "You are not the owner");
        require(amount <= address(this).balance, "Not enough ETH balance");
        payable(owner).transfer(amount);
    }
    
    function getDAIbalance() public view returns(uint){
        return DAI.balanceOf(address(this)) / 1000000000000000000;
    }

    function getprices() public view returns(int , int , int ) {
        int ethusd = ETHUSD.getLatestPrice();
        int btcusd = BTCUSD.getLatestPrice();
        int daiusd = DAIUSD.getLatestPrice();

        return (ethusd,btcusd,daiusd);
    }

    function getaccountoptionslength(address account) public view returns (uint) {
        return Accountbets[account].length;
    }