<?php

/*
 * Copyright (C) 2021 Echedey López Romero <elr@disroot.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

class User {

    private string $Id;
    private string $Name;
    private string $EMail;
    private string $Date;
    private int $Privileges;

    public function __construct(string $Id, string $Name, string $EMail, string $Date, int $Privileges) {
        $this->Id = $Id;
        $this->Name = $Name;
        $this->Date = $Date;
        $this->EMail = $EMail;
        $this->Privileges = $Privileges;
    }
    
    public function GetId(): string {
        return $this->Id;
    }

    public function GetName(): string {
        return $this->Name;
    }

    public function GetEMail(): string {
        return $this->EMail;
    }
    
    public function GetDate(): string {
        return $this->Date;
    }
    
    public function GetPrivileges(): int {
        return $this->Privileges;
    }
    
    private function GetPrivilegesType(): string {
        $Type = '';
        
        switch ($this->Privileges) {
            case 0:
                $Type = 'Administrator';
                break;
            case 1:
                $Type = 'Author';
                break;
            case 2:
                $Type = 'Subscriber';
                break;
        }
        
        return $Type;
    }
    
    public function SetId(string $Id): void {
        $this->Id = $Id;
    }

    public function SetName(string $Name): void {
        $this->Name = $Name;
    }

    public function SetEMail(string $EMail): void {
        $this->EMail = $EMail;
    }
    
    public function SetDate(string $Date): void {
        $this->Date = $Date;
    }
    
    public function SetPrivileges(int $Privileges): void {
        $this->Privileges = $Privileges;
    }

    public function Render(): string {
        $HTML = '';
        
        $HTML .= '<div>' . PHP_EOL;
        $HTML .= '<span>' . $this->Name . ' ('. $this->GetPrivilegesType() .')' . '</span>' . PHP_EOL;
        $HTML .= '<span>' . $this->EMail . '</span>' . PHP_EOL;
        $HTML .= '<span>' . $this->Date . '</span>' . PHP_EOL;
        $HTML .= '</div>' . PHP_EOL;
        
        return $HTML;
    }
    
}
