<?php

class Admin {

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

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

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

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

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

    /**
     * METHODDESCRIPTION
     *
     * @access public
     * @return RETURNTYPE RETURNDESCRIPTION
     */
    public function getIp() {
        return $this->ip;
    }

    /**
     * METHODDESCRIPTION
     *
     * @access public
     * @param ARGTYPE $ip ARGDESCRIPTION
     */
    public function setIp($ip) {
        $this->ip = $ip;
    }

    /**
     * METHODDESCRIPTION
     *
     * @access public
     * @return RETURNTYPE RETURNDESCRIPTION
     */
    public function getLastLogin() {
        return $this->lastLogin;
    }

    /**
     * METHODDESCRIPTION
     *
     * @access public
     * @param ARGTYPE $lastLogin ARGDESCRIPTION
     */
    public function setLastLogin($lastLogin) {
        $this->lastLogin = $lastLogin;
    }

    /**
     * METHODDESCRIPTION
     *
     * @access public
     * @return RETURNTYPE RETURNDESCRIPTION
     */
    public function getEmail() {
        return $this->email;
    }

    /**
     * METHODDESCRIPTION
     *
     * @access public
     * @param ARGTYPE $email ARGDESCRIPTION
     */
    public function setEmail($email) {
        $this->email = $email;
    }

    /**
     * METHODDESCRIPTION
     *
     * @access public
     * @return RETURNTYPE RETURNDESCRIPTION
     */
    public function getPassword() {
        return $this->password;
    }

    /**
     * METHODDESCRIPTION
     *
     * @access public
     * @param ARGTYPE $password ARGDESCRIPTION
     */
    public function setPassword($password) {
        $this->password = $password;
    }

    /**
     * METHODDESCRIPTION
     *
     * @access public
     * @return RETURNTYPE RETURNDESCRIPTION
     */
    public function getUsername() {
        return $this->username;
    }

    /**
     * METHODDESCRIPTION
     *
     * @access public
     * @param ARGTYPE $username ARGDESCRIPTION
     */
    public function setUsername($username) {
        $this->username = $username;
    }

    public static function getCurrentAdmin($username = NULL) {
        if (is_null($username)) {
            $username = isset($_SESSION[ADMIN]) ? $_SESSION[ADMIN] : NULL;
        }
        $db = new DatabaseConn();
        $link = $db->connect();
        $result = mysqli_query($link, "select * from `admin` where `username` = '$username'");
        $admin = mysqli_fetch_object($result, Admin::class);
        return $admin;
    }

    public static function loginAdmin($username, $password) {
        $db = new DatabaseConn();
        $link = $db->connect();
        $result = mysqli_query($link, "select * from `admin` where `username` = '$username' and password = '$password'");
        $admin = mysqli_fetch_object($result, Admin::class);
        return $admin;
    }

}
