<?php

namespace App\Models;

use App\Models\BaseModel;

class InventoryCategory extends BaseModel
{
    protected $table = 'inventory_categories';

    // ✅ CI: useTimestamps = true (created_at/updated_at)
    public $timestamps = true;

    protected $fillable = [
        'type',
        'name',
        'description',
        'grade_min',
        'grade_max',
        'created_at',
        'updated_at',
    ];

    protected $casts = [
        'grade_min' => 'integer',
        'grade_max' => 'integer',
    ];

    /**
     * Equivalent of CI optionsForType()
     * Returns array rows: id, name, description, grade_min, grade_max
     */
    public static function optionsForType(string $type): array
    {
        return static::query()
            ->select(['id', 'name', 'description', 'grade_min', 'grade_max'])
            ->where('type', $type)
            ->orderBy('name', 'asc')
            ->get()
            ->toArray();
    }
}