<?php
    namespace Model;
    use Entity\User;
    use Gateway\UserGateway;

    class UserModel
    {
        private UserGateway $gateway;

        public function __construct(UserGateway $gate){
            $this->gateway = $gate;
        }

        public function insertUser(string $username,string $email,string $passwd) : User{
            global $rep,$image;
            $id = $this->gateway->insert($username,$email,$passwd);
            $u = new User($id,$usename,$passwd,$rep.$image['default'],$email);
        }

        public function deletUser(string $id) : bool{
            return $this->gateway->delete($id);
        }


        // public function getFavoriteUser(string $id) : array{
        //     $res = array();
        //     $data = $this->gateway->getFavorite($id);
        //     foreach ($data as $favoris) {
        //         $res[] = new Quote();
        //     }
        // }

        public function getDataUser(int $id){
            $res = $this->gateway->findDataUser($id);
            foreach($res as $sources){
                $src[] = new sourceEntity(
                    $sources['id_user'],
                    $sources['username'],
                    $sources['pssword'],
                    $sources['img'],
                    $sources['email']
                );
            }
            return $src;
        }


        public function setUsername(int $id, string $newUsername){
            $res = $this->gateway->updateUsername($id,$newUsername);
            $src[] = new sourceEntity($res['username']);

            return $src;
        }

        public function setEmail(int $id, string $newEmail){
            $res = $this->gateway->updateEmail($id,$newEmail);
            $src[] = new sourceEntity($res['email']);

            return $src;
        }

        public function setImg(int $id, int $newImg){
            $res = $this->gateway->updateImg($id,$newImg);
            $src[] = new sourceEntity($res['img']);

            return $src;
        }

        public function setPassWd(int $id, string $newPassWd){
            $res = $this->gateway->updatePasswd($id,$newPassWd);
            $src[] = new sourceEntity($res['pssword']);

            return $src;
        }
    }

?>
