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

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

        protected $table = 'clients_urls';

        protected $schema = array(
            array('name' => 'id', 'type' => 'int'),
            array('name' => 'client_id', 'type' => 'int'),
            array('name' => 'code', 'type' => 'text'),
            array('name' => 'attempts', 'type' => 'int'),
            array('name' => 'expired', 'type' => 'enum', 'default' => 'F'),
            array('name' => 'active', 'type' => 'enum', 'default' => 'F'),
            array('name' => 'created_at', 'type' => 'datetime', 'default' => ':NOW()')
        );

        protected $validate = array(
            'rules' => array(
                'client_id' => array(
                    'pjActionRequired' => true,
                    'pjActionNotEmpty' => true,
                    'pjActionNumeric'  => true
                ),
                'code'      => array(
                    'pjActionRequired' => true,
                    'pjActionNotEmpty' => true
                ),
                'expired'   => array(
                    'pjActionRequired' => true,
                    'pjActionNotEmpty' => true
                )
            )
        );

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