<?php
class TruckTypes extends Model
{
    public function allActive(): array
    {
        $db = new DB();
        return $db->mySelect(
            "SELECT c0d, slug, display_name, description, sort_order
               FROM truck_types
              WHERE active = 1 AND tenant_id = :t
           ORDER BY sort_order ASC, display_name ASC",
            [':t' => defined('DEFAULT_TENANT_ID') ? DEFAULT_TENANT_ID : 1]
        ) ?: [];
    }

    public function byId(int $id): array
    {
        $db = new DB();
        $rs = $db->mySelect("SELECT * FROM truck_types WHERE c0d = :id LIMIT 1", [':id' => $id]);
        return $rs[0] ?? [];
    }
}
