<?php

namespace App\Http\Requests\Tanks;

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

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

    public function rules(): array
    {
        $userId = (int) auth('api')->id();

        return [
            'number' => [
                'nullable',
                'integer',
                'min:1',
                Rule::unique('tanks', 'number')->where(fn ($q) => $q->where('user_id', $userId)),
            ],
            'name' => ['required', 'string', 'max:255'],
            'volume_liters' => ['required', 'integer', 'min:1'],
            'max_capacity' => ['nullable', 'integer', 'min:0'],
            'status' => ['nullable', 'string', 'max:50'],
            'physical_notes' => ['nullable', 'string'],
            'location' => ['nullable', 'string', 'max:255'],
            'tank_type' => ['nullable', 'string', 'max:50'],
        ];
    }
}
