<?php

namespace Modules\SpecialAttendance\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StoreTardyRuleRequest extends FormRequest
{
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'title' => [
                'required',
                'max:255',
                Rule::unique('tardy_rules', 'title')->where('company_id', auth()->user()->company_id)->ignore($this->id),
            ],
            'threshold_minutes' => 'required|integer',
            'threshold_days' => 'nullable|integer',
            'deduction_days' => ['required', 'numeric', 'regex:/^\d+(\.\d{1,2})?$/'],
            'description' => 'nullable|string|max:255',
            'status_id' => 'nullable|exists:statuses,id',
        ];
    }

    public function messages()
    {
        return [
            'title.required' => _trans('validation.The title is required.'),
            'title.max' => _trans('validation.The title may not be greater than 255 characters.'),
            'title.unique' => _trans('validation.The title has already been taken.'),
            'threshold_minutes.required' => _trans('validation.The threshold minutes are required.'),
            'threshold_minutes.integer' => _trans('validation.The threshold minutes must be an integer.'),
            'threshold_days.integer' => _trans('validation.The threshold days must be an integer.'),
            'deduction_days.required' => _trans('validation.The deduction days are required.'),
            'deduction_days.numeric' => _trans('validation.The deduction days must be a number.'),
            'deduction_days.regex' => _trans('validation.The deduction days must be a valid decimal value.'),
            'description.string' => _trans('validation.The description must be a string.'),
            'description.max' => _trans('validation.The description may not be greater than 255 characters.'),
            'status_id.exists' => _trans('validation.The selected status is invalid.'),
        ];
    }
}
