<?php

namespace App\Http\Controllers\Api;

use App\Models\Supplier;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class SupplierController extends BaseApiController
{
    protected string $model = Supplier::class;
    protected array $searchable = ['name', 'contactPerson', 'email', 'category'];
    protected array $filters = ['status' => 'status', 'category' => 'category'];

    protected function rules(Request $request, ?Model $model = null): array
    {
        $required = $model ? 'sometimes' : 'required';
        return [
            'name' => "$required|string",
            'contactPerson' => 'nullable|string',
            'email' => 'nullable|email',
            'phone' => 'nullable|string',
            'address' => 'nullable|string',
            'category' => 'nullable|string',
            'rating' => 'nullable|numeric|min:0|max:5',
            'status' => 'nullable|string',
        ];
    }
}
