<?php
    namespace Entity;

    class User{

        private int $id;
        private string $username;
        private string $passwd;
        private string $hidenPasswd;
        private int $img;
        private string $email;

        /**
         * @param int $id
         * @param string $username
         * @param string $passwd
         * @param string $hidenPasswd
         * @param int $img
         * @param string $email
         */
        public function __construct(int $id, string $username, string $passwd, int $img, string $email)
        {
            $this->id = $id;
            $this->username = $username;
            $this->passwd = $passwd;
            $this->hidenPasswd = hidenPasswd($passwd);
            $this->img = $img;
            $this->email = $email;
        }

        /**
         * @return string
         */
        public function getId(): int
        {
            return $this->id;
        }

        /**
         * @param string $id
         */
        public function setId(int $id): void
        {
            $this->id = $id;
        }

        /**
         * @return string
         */
        public function getUsername(): string
        {
            return $this->username;
        }

        /**
         * @param string $username
         */
        public function setUsername(string $username): void
        {
            $this->username = $username;
        }

        /**
         * @return string
         */
        public function getImg(): int
        {
            return $this->img;
        }

        /**
         * @param string $img
         */
        public function setImg(int $img): void
        {
            $this->img = $img;
        }

        /**
         * @return string
         */
        public function getEmail(): string
        {
            return $this->email;
        }

        /**
         * @param string $email
         */
        public function setEmail(string $email): void
        {
            $this->email = $email;
        }

        /**
         * @return string
         */
        public function getPasswd(): string
        {
            return $this->passwd;
        }

        /**
         * @return string
         */
        public function getHidenPasswd(): string
        {
            return $this->hidenPasswd;
        }

        /**
         * @param string $passwd
         */
        public function setPasswd(string $passwd): void
        {
            $this->passwd = $passwd;
            $this->hidenPassWd = hidenPassWd($passwd);
        }



    }
    // ============================================ En attente du Model ============================================
    /*$dsn = "pgsql:host=londres;dbname=dblebeaulato";
    $username = "lebeaulato";
    $password = "";
    
    $con = new Connection($dsn,$username,$password);

    $query = 'SELECT * FROM Users WHERE id_user=:idUser';
    $con->executeQuery($query, array(':idUser'=>array('U003', PDO::PARAM_STR)));
    $result = $con->getResults();

    $u = new User($result[0]['id_user'],$result[0]['username'], $result[0]['pssword'], '../images/imageProfil.png', $result[0]['email']); 




    //UPDATE username User
    $query = 'UPDATE Users SET username=:newUsername WHERE id_user=:idUser';
    $con->executeQuery($query, array(':idUser'=>array('U003', PDO::PARAM_STR), ':newUsername'=> array('Hello', PDO::PARAM_STR)));
    $queryReponse = 'SELECT username FROM Users WHERE id_user=:idUser';

    $con->executeQuery($queryReponse, array(':idUser'=>array('U003', PDO::PARAM_STR)));
    $result = $con->getResults();
    $u->setUsername($result[0]['username']);


    //UPDATE email User
    $query = 'UPDATE Users SET email=:newEmail WHERE id_user=:idUser';
    $con->executeQuery($query, array(':idUser'=>array('U003', PDO::PARAM_STR), ':newEmail'=> array('hello@gmail.com', PDO::PARAM_STR)));
    $queryReponse = 'SELECT email FROM Users WHERE id_user=:idUser';

    $con->executeQuery($queryReponse, array(':idUser'=>array('U003', PDO::PARAM_STR)));
    $result = $con->getResults();
    $u->setEmail($result[0]['email']); 

    //UPDATE passwd User
    $query = 'UPDATE Users SET pssword=:newPassWd WHERE id_user=:idUser';
    $con->executeQuery($query, array(':idUser'=>array('U003', PDO::PARAM_STR), ':newPassWd'=> array('TestMotDePasssse', PDO::PARAM_STR)));

    $queryReponse = 'SELECT pssword FROM Users WHERE id_user=:idUser';
    $con->executeQuery($queryReponse, array(':idUser'=>array('U003', PDO::PARAM_STR)));
    $result = $con->getResults();
    $u->setPasswd($result[0]['pssword']); /*Test*/

// ================================================================================================================

    
    
    function hidenPassWd(string $passwd){
        if(strlen($passwd) >= 16) return str_repeat('*', 16);
        return str_repeat('*', strlen($passwd)); 
    }
?>
