<?php
class TruckDocTypes extends Model
{
    public function allActive(): array
    {
        $db = new DB();
        return $db->mySelect(
            "SELECT c0d, slug, display_name, has_expiry, warn_days, required, sort_order
               FROM truck_doc_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_doc_types WHERE c0d = :id LIMIT 1", [':id' => $id]);
        return $rs[0] ?? [];
    }
}
