<?php

namespace App\Http\Requests\V1\WorkSetting;

use App\Models\Tenants\WorkSetting;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UpdateWorkSettingRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'work_type' => ['sometimes', 'string', Rule::in(WorkSetting::WORK_TYPES)],
            'standard_hours' => ['sometimes', 'integer', 'min:1', 'max:168'],
            'overtime_hours' => ['sometimes', 'integer', 'min:0', 'max:52'],
            'overtime_limit' => ['sometimes', 'integer', 'min:0', 'max:100'],
            'work_days' => ['sometimes', 'array'],
            'work_days.*' => ['string', Rule::in(['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'])],
            'start_time' => ['sometimes', 'date_format:H:i:s'],
            'end_time' => ['sometimes', 'date_format:H:i:s', 'after:start_time'],
            'break_minutes' => ['sometimes', 'integer', 'min:0', 'max:180'],
            'break_start' => ['nullable', 'date_format:H:i:s'],
            'break_end' => ['nullable', 'date_format:H:i:s', 'after:break_start'],
        ];
    }

    public function messages(): array
    {
        return [
            'work_type.in' => __('error.work_setting.invalid_work_type'),
            'end_time.after' => __('error.work_setting.end_time_after_start'),
            'break_end.after' => __('error.work_setting.break_end_after_start'),
        ];
    }
}
