<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class CouponRequest extends FormRequest
{
    private $table            = 'coupon';

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $id = $this->id;

        $condCode = "bail|required|size:6|unique:$this->table,code";
        $condNumeric = "bail|required|numeric";
        $condDate = "bail|required|date";
        // $condThumb= 'bail|required|image|max:500';

        if (!empty($id)) {
            $condCode .= ",$id";
        }
        // "value_percent" => "1"
        //   "value_price" => "1"
        //   "value_use" => "1"
        //   "date_start" => "2023-02-05"
        //   "date_end" => "2023-02-05"
        //   "total_start" => "1"
        //   "total_end" => "1"
        return [
            'code'        => $condCode,
            'value_percent'      => $condNumeric,
            'value_price'      => $condNumeric,
            'total_use'      => $condNumeric,
            'date_start'      => $condDate,
            'date_end'      => $condDate,
            'total_start'      => $condNumeric,
            'total_end'      => $condNumeric,
            // 'status'      => 'bail|in:active,inactive',
        ];
    }

    public function messages()
    {
        return [
            // 'name.required' => 'Name không được rỗng',
            // 'name.min'      => 'Name :input chiều dài phải có ít nhất :min ký tứ',
        ];
    }
    public function attributes()
    {
        return [
            // 'description' => 'Field Description: ',
        ];
    }
}
