contract DozerPassV2 is ReentrancyGuard, Ownable {
    using SafeMath for uint256;

    string primeType;
    uint256 priceTypeIdx;
    uint256 maxPrimeDay;

    uint256 internal priceCoin;
    uint256 internal priceWall;
    uint256 internal priceHikimo;
    uint256 internal priceTwinky;
    uint256 internal pricePeppa;
    uint256 internal priceNick;


    mapping (address => uint256) private userPrimeTypes; // 1 coin, 2 wall, 3 hikimo, 4 twinky, 5 peppa, 6 nick
    mapping (address => uint256[]) private userPrimeDays;

    event EventWithdraw(address _to, uint256 _value);
    event EventPrime(address _to, uint256 _value, string _primeType);
    event EventPrimeOpen(address _to, string _primeType, uint256 _day);

    constructor (
      uint256 _priceCoin,
      uint256 _priceWall,
      uint256 _priceHikimo,
      uint256 _priceTwinky,
      uint256 _pricePeppa,
      uint256 _priceNick,
      uint256 _maxPrimeDay
    ) public {
      priceCoin = _priceCoin;
      priceWall = _priceWall;
      priceHikimo = _priceHikimo;
      priceTwinky = _priceTwinky;
      pricePeppa = _pricePeppa;
      priceNick = _priceNick;
      maxPrimeDay = _maxPrimeDay;
    }

    // buy member prime
    function () external payable {
      require (
        address(msg.sender) != address(0) &&
        address(msg.sender) != address(this), 'wrong address');
      require (
        uint256(msg.value) == priceCoin ||
        uint256(msg.value) == priceWall ||
        uint256(msg.value) == priceHikimo ||
        uint256(msg.value) == priceTwinky ||
        uint256(msg.value) == pricePeppa ||
        uint256(msg.value) == priceNick, 'wrong price');

      if (uint256(msg.value) == priceCoin) {
          primeType = 'coin';
          priceTypeIdx = 1;
      } else if (uint256(msg.value) == priceWall) {
          primeType = 'wall';
          priceTypeIdx = 2;
      } else if (uint256(msg.value) == priceHikimo) {
          primeType = 'hikimo';
          priceTypeIdx = 3;
      } else if (uint256(msg.value) == priceTwinky) {
          primeType = 'twinky';
          priceTypeIdx = 4;
      } else if (uint256(msg.value) == pricePeppa) {
          primeType = 'peppa';
          priceTypeIdx = 5;
      } else if (uint256(msg.value) == priceNick) {
          primeType = 'nick';
          priceTypeIdx = 6;
      }

      userPrimeTypes[msg.sender] = priceTypeIdx;
      emit EventPrime(msg.sender, msg.value, primeType);
  }


  function primeOpen(string memory _primeType, uint256 _day) public {
    require(userPrimeTypes[msg.sender] != 0, 'do not open');

    userPrimeDays[msg.sender].push(_day);
    emit EventPrimeOpen(msg.sender, _primeType, _day);

    // reset
    if(userPrimeDays[msg.sender].length == maxPrimeDay){
      userPrimeDays[msg.sender].length = 0;
    }
  }


  function getUserPrimeType() public view returns (uint256) {
      return userPrimeTypes[msg.sender];
  }
  function getUserPrimeDay() public view returns (uint256[] memory) {
      return userPrimeDays[msg.sender];
  }


  // withdraw
  function withdraw (uint256 _amount, address payable _account)
    public onlyOwner {
    require (
      address(_account) != address(0) &&
      address(_account) != address(this), 'wrong address');
    require(_amount <= address(this).balance, 'wrong price');

    _account.transfer(_amount);
    emit EventWithdraw(_account, _amount);
  }
}
function withdraw (uint256 _amount, address payable _account)
  public onlyOwner {
  require (
    address(_account) != address(0) &&
    address(_account) != address(this), 'wrong address');
  require(_amount <= address(this).balance, 'wrong price');

  _account.transfer(_amount);
  emit EventWithdraw(_account, _amount);
}

// withdraw