<?php
    if (!defined("ROOT_PATH")) {
        header("HTTP/1.1 403 Forbidden");
        exit;
    }

    class pjClientModel extends pjAppModel
    {
        protected $primaryKey = 'id';

        protected $table = 'clients';

        protected $schema = array(
            array('name' => 'id', 'type' => 'int'),
            array('name' => 'tutor_id', 'type' => 'int', 'default' => ':NULL'),
            array('name' => 'username', 'type' => 'varchar'),
            array('name' => 'email', 'type' => 'varchar'),
            array('name' => 'password', 'type' => 'blob', 'encrypt' => 'AES'),
            array('name' => 'active', 'type' => 'enum', 'default' => 'F'),
            array('name' => 'timezone', 'type' => 'varchar', 'default' => ':NULL')
        );

        protected $validate = array(
            'rules' => array(
                'username' => array(
                    'pjActionRequired' => true
                ),
                'password' => array(
                    'pjActionRequired' => true,
                    'pjActionNotEmpty' => true
                ),
                'email'    => array(
                    'pjActionEmail'    => true,
                    'pjActionRequired' => true,
                    'pjActionNotEmpty' => true
                )
            )
        );

        public static function factory($attr = array())
        {
            return new self($attr);
        }
    }