<?php

namespace Modules\SpecialAttendance\Http\Requests;

use App\Helpers\CoreApp\Traits\ApiReturnFormatTrait;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;

class UpdateTardyRequestRequest extends FormRequest
{
    use ApiReturnFormatTrait;

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'reason' => ['required', 'max:255'],
            'attachment' => ['nullable', 'file', 'mimes:png,jpg,jpeg,pdf'],
        ];
    }

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

    public function messages()
    {
        return [
            'reason.required' => _trans('common.Reason is required'),
            'reason.max' => _trans('common.Reason may not be greater than :max characters'),
            'attachment.file' => _trans('common.Attachment must be a file'),
            'attachment.mimes' => _trans('common.Attachment must be a file of type: :values'),
        ];
    }

    /**
     * Get the error messages json response for the defined validation rules.
     *
     * @return array
     */
    public function failedValidation(Validator $validator)
    {
        throw new HttpResponseException($this->responseWithError(__('Validation Error'), $validator->errors()->all(), 422));
    }
}
