<?php

namespace App\Http\Requests\Coupon;

use Illuminate\Foundation\Http\FormRequest;

class CouponCreateRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        if (auth()->user()->hasRole('administrator')) {
            return TRUE;
        } else {
            return FALSE;
        }
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'name' => 'required|string',
            'code' => 'required|unique:coupons,code,',
            'type' => 'required|in:1,2',
            'amount' => 'required|numeric|min:0|not_in:0',
            'start_date' => 'nullable|date|after_or_equal:today',
            'end_date' => 'nullable|date|after:start_date|after_or_equal:today',
            'max_uses' => 'nullable|numeric|min:0|not_in:0',
            'use_once' => 'required|boolean',
            'products.*' => 'nullable',
        ];
    }
}
