<?php

namespace App\Http\Requests;

use App\Models\Impresora;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StoreImpresoraRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can('administracion.areas') ?? false;
    }

    public function rules(): array
    {
        return [
            'area_id' => ['required', 'integer', 'exists:areas,id'],
            'codigo' => ['nullable', 'string', 'max:64', 'alpha_dash', Rule::unique('impresoras', 'codigo')],
            'nombre' => ['required', 'string', 'max:255'],
            'nombre_sistema' => ['required', 'string', 'max:255'],
            'ip' => ['nullable', 'string', 'max:45'],
            'puerto' => ['nullable', 'integer', 'min:1', 'max:65535'],
            'tipo_ticket' => ['required', 'string', Rule::in([Impresora::TIPO_VENTA, Impresora::TIPO_COCINA])],
            'activa' => ['sometimes', 'boolean'],
            'es_por_defecto' => ['sometimes', 'boolean'],
            'ancho_papel' => ['nullable', 'integer', 'min:32', 'max:120'],
        ];
    }
}
