<?php

class Wallet {

    /**
     * PROPDESCRIPTION
     *
     * @access private
     * @var PROPTYPE
     */
    private $id;

    /**
     * PROPDESCRIPTION
     *
     * @access private
     * @var PROPTYPE
     */
    private $amount;

    /**
     * PROPDESCRIPTION
     *
     * @access private
     * @var PROPTYPE
     */
    private $date;

    /**
     * PROPDESCRIPTION
     *
     * @access private
     * @var PROPTYPE
     */
    private $proof;

    /**
     * PROPDESCRIPTION
     *
     * @access private
     * @var PROPTYPE
     */
    private $sender;

    /**
     * PROPDESCRIPTION
     *
     * @access private
     * @var PROPTYPE
     */
    private $status;

    /**
     * PROPDESCRIPTION
     *
     * @access private
     * @var PROPTYPE
     */
    private $user;

    function setId($id) {
        $this->id = $id;
    }

    function getId() {
        return $this->id;
    }

    function setAmount($amount) {
        $this->amount = $amount;
    }

    function getAmount() {
        return $this->amount;
    }

    function setDate($date) {
        $this->date = $date;
    }

    function getDate() {
        return $this->date;
    }

    function setProof($proof) {
        $this->proof = $proof;
    }

    function getProof() {
        return $this->proof;
    }

    function setSender($sender) {
        $this->sender = $sender;
    }

    function getSender() {
        return $this->sender;
    }

    function setStatus($status) {
        $this->status = $status;
    }

    function getStatus() {
        return $this->status;
    }

    function setUser($user) {
        $this->user = $user;
    }

    function getUser() {
        return $this->user;
    }

    /**
     * Get all wallet deposits on the system, if email is provided
     * It fetches the wallet deposit of the particular user.
     *
     * @param mysqli $link
     * @access public
     *
     * @return Wallet Array of wallets or null;
     */
    public static function getWalletDeposit($link, $email = NULL) {
        if (!$link instanceof mysqli) {
            throw new Exception("Bad arguments passed: \n");
        }
        if (is_null($email)) {
            $query = "select * from wallet ORDER BY `date`  desc";
        } else {
            $query = "select * from wallet WHERE `user` = '$email' order by `date` desc";
        }
        $wallets = array();
        $result = mysqli_query($link, $query);
        if (mysqli_num_rows($result) === 0) {
            return NULL;
        }
        for ($i = 0; $i < mysqli_num_rows($result); $i++) {
            $wallet = mysqli_fetch_object($result, Wallet::class);
            array_push($wallets, $wallet);
            if (mysqli_more_results($link)) {
                mysqli_next_result($link);
            }
        }
        return $wallets;
    }

    public static function getWalletHistory($link, $email = NULL) {
        if (!$link instanceof mysqli) {
            throw new Exception("Bad arguments passed: \n");
        }
        if (is_null($email)) {
            $query = "select * from wallet";
        } else {
            $query = "select * from wallet WHERE `user` = '$email'";
        }
        $wallets = array();
        $result = mysqli_query($link, $query);
        if (mysqli_num_rows($result) === 0) {
            return NULL;
        }
        for ($i = 0; $i < mysqli_num_rows($result); $i++) {
            $wallet = mysqli_fetch_object($result, Wallet::class);
            array_push($wallets, $wallet);
            if (mysqli_more_results($link)) {
                mysqli_next_result($link);
            }
        }
        return $wallets;
    }

}
