<?php namespace App\Http\Controllers;

use App\Models\Coupons;

class CouponsController extends DataManangeCtrl
{
    protected $layout = "layouts.main";
    protected $data = array();
    public $module = 'coupons';
    static $per_page = '10';

    public function __construct()
    {
        $this->model = new Coupons();

        parent::__construct();
    }

    /**
     * Add server-side validation for YK-567, YK-566 and YK-556.
     *
     * @param array $forms
     * @return array
     */
    public function validateForm($forms = array())
    {
        $rules = parent::validateForm($forms);

        $rules['coupon_rank'] = [
            'nullable',
            'integer',
            'between:1,10',
        ];

        // YK-566: Verified is mandatory - the hidden/checkbox pair always
        // submits 0 or 1, so this only rejects a tampered or missing value.
        $rules['verified'] = [
            'required',
            'boolean',
        ];

        // YK-556: Initial Usage Count is optional but must be a whole
        // number >= 0 when provided.
        $rules['initial_usage_count'] = [
            'nullable',
            'integer',
            'min:0',
        ];

        return $rules;
    }
}
