<?php
    class User extends Model {
        // ===========
        // = Statics =
        // ===========
        public static function tryLogin($login) {
            return new static();
        }

        protected static $table_name = 'USER';

        public static function create($post) {
            parent::exec('USER_CREATE', [':firstname' => $post->firstname,
                                         ':lastname' => $post->lastname,
                                         ':login' => $post->login,
                                         ':email' => $post->email,
                                         ':password' => password_hash($post->password, PASSWORD_BCRYPT),
                                         ':role' => $post->role]);
        }

        public static function getList() {
            $stm = parent::exec('USER_GET_LIST');
            return $stm->fetchAll();
        }

        public static function getWithId($id) {
            $stm = parent::exec('USER_GET_WITH_ID', [':id' => $id]);
            return $stm->fetch();
        }

        public static function getWithLogin($login) {
            $stm = parent::exec('USER_GET_WITH_LOGIN', [':login' => $login]);
            return $stm->fetch();
        }

        public static function update($put, $id) {
            parent::exec('USER_UPDATE', [':email' => $put->email, ':id' => $id]);
        }

        public static function delete($id) {
            parent::exec('USER_DELETE', [':id' => $id]);
        }
    }
?>