<?php

namespace App\Modules\HR\Shifts\Requests;

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

class StoreShiftSwapRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can('shifts.assign') === true;
    }

    public function rules(): array
    {
        $tenantId = $this->user()?->tenant_id;
        $assignment = Rule::exists('employee_shift_assignments', 'id')
            ->where(fn ($query) => $query->where('tenant_id', $tenantId));

        return [
            'assignment_a' => ['required', 'integer', $assignment],
            'assignment_b' => ['required', 'integer', 'different:assignment_a', $assignment],
            'date' => ['required', 'date'],
        ];
    }
}
