<?php

namespace App\Models;

use CodeIgniter\Model;

class InventoryItemModel extends Model
{
protected $table      = 'inventory_items';
    protected $primaryKey = 'id';

    protected $returnType    = 'array';
    protected $useSoftDeletes = false;

    protected $useTimestamps = true;
    protected $createdField  = 'created_at';
    protected $updatedField  = 'updated_at';

    // IMPORTANT: include everything you ever update/insert
    protected $allowedFields = [
        'type',
        'category_id',
        'name',
        'description',
        'quantity',            // <- recalcQuantity updates this
        'unit',
        'condition',
        'isbn',
        'edition',
        'sku',
        'notes',

        // audit
        'updated_by',

        // classroom state buckets
        'good_qty',
        'needs_repair_qty',
        'need_replace_qty',
        'cannot_find_qty',
    ];


    protected $validationRules = [
        'type'        => 'required|in_list[classroom,book,office,kitchen]',
        'name'        => 'required|min_length[2]',
        'quantity'    => 'permit_empty|integer',
        'unit_price'  => 'permit_empty|decimal',
    ];
}
