<?php
require_once('Database.php');
class UserAccount extends Database{
    public $Id;
    public $FullName;
    public $Email;
    public $Phone;
    public $Password;
    public $IsAdmin;
    public $Token;
    public $Avatar;
    public $CompanyName;
    public $IsCompany;

  public function InsertRecord(){
    if($this->IsCompany==""){
      $this->IsCompany = 0;
    }
    if($this->IsAdmin==""){
      $this->IsAdmin = 0;
    }
    $Query = "INSERT INTO UserAccount (FullName, Email, Phone, Password, IsAdmin, Token, CompanyName, IsCompany) 
                VALUES ('$this->FullName', '$this->Email', '$this->Phone', '$this->Password', $this->IsAdmin, '$this->Token', '$this->CompanyName', $this->IsCompany)";
    return $this->ExecuteQueryReturnId($Query);
  }

    public function UpdateRecord(){
        $Query = "UPDATE UserAccount SET 
                    Email = '$this->Email',
                    FullName = '$this->FullName',
                    Phone = '$this->Phone',
                    CompanyName = '$this->CompanyName'
                     WHERE Id = $this->Id;";
        return $this->ExecuteQuery($Query);
    }

  public function DeleteRecord(){
    $Query = "UPDATE UserAccount SET 
                    Status = 0
                     WHERE Id = $this->Id;";
    return $this->ExecuteQuery($Query);
  }

  public function UpdateAvatar(){
    $Query = "UPDATE UserAccount SET 
                    Avatar = '$this->Avatar'
                     WHERE Id = $this->Id;";
    return $this->ExecuteQuery($Query);
  }

    public function UpdatePassword(){
        $Query = "UPDATE UserAccount SET Password = '$this->Password' WHERE Id = $this->Id;";
        //echo $Query;
        return $this->ExecuteQuery($Query);
    }

    public function UpdateToken(){
      $Query = "UPDATE UserAccount SET Token = '$this->Token' WHERE Id = $this->Id;";
      //echo $Query;
      return $this->ExecuteQuery($Query);
    }

    public function GetRecord(){
        $Query = "SELECT *  FROM UserAccount U WHERE U.Id = $this->Id;";
        //echo $Query;
        return $this->ExecuteUniqueReader($Query);
    }

    public function GetRecordLogin(){
      $Query = "SELECT *  FROM UserAccount U WHERE U.Email = '$this->Email' AND U.Password='$this->Password';";
      //echo $Query;
      return $this->ExecuteUniqueReader($Query);
    }

  public function GetRecordByToken(){
    $Query = "SELECT *  FROM UserAccount U WHERE U.Token = '$this->Token';";
    //echo $Query;
    return $this->ExecuteUniqueReader($Query);
  }

  public function GetRecordByEmail(){
    $Query = "SELECT *  FROM UserAccount U WHERE U.Email = '$this->Email';";
    //echo $Query;
    return $this->ExecuteUniqueReader($Query);
  }

  public function GetRecords($isCompany = 0){
    $Query = "SELECT *  FROM UserAccount U WHERE Status = 1 AND IsCompany = $isCompany AND IsAdmin=0";
    //echo $Query;
    return $this->ExecuteReader($Query);
  }

  public function GetRecordsAdmin(){
    $Query = "SELECT *  FROM UserAccount U WHERE Status = 1 AND IsAdmin = 1";
    //echo $Query;
    return $this->ExecuteReader($Query);
  }
}