<?php

if (!defined('WD')) { define('WD', dirname(__DIR__, 2)); }

require_once WD . '/classes/db.php';
require_once WD . '/classes/object_property.php';
require_once WD . '/traits/db_object_t.php';
require_once WD . '/objects/department_lanes_o.php';
require_once WD . '/modules/selfserve/helpers/selfserve_lane_status.php';

use modules\selfserve\helpers\selfserve_lane_status;

class TestDepartmentLane extends \objects\department_lanes_o
{
    public function getLaneStatus(): selfserve_lane_status
    {
        // Return a deterministic status to avoid external dependencies
        return selfserve_lane_status::AVAILABLE;
    }
}

function assert_true($cond, $msg)
{
    if ($cond) {
        echo "✔ $msg\n";
    } else {
        echo "✘ $msg\n";
        exit(1);
    }
}

// Initialize a lane object in fake/id<0 mode to avoid DB access
$lane = new TestDepartmentLane();
$lane->structure(); // ensure table is set
$lane->id = -1;     // enable fake value mode in object_property
$lane->getObjectProperties();

// Set fake values
$lane->department->set(7);
$lane->name->set('Test Lane');
$lane->relay_in_id->set('shelly-relay-in-001');
$lane->relay_out_id->set('shelly-relay-out-001');
$lane->relay_machine_id->set('shelly-relay-machine-001');
$lane->dynamic_image_id->set(42);
$lane->created_at->set('2026-01-01 00:00:00');
$lane->updated_at->set('2026-01-02 00:00:00');

// Serialize and validate
$arr = $lane->asArray();

assert_true(array_key_exists('dynamic_image_id', $arr), 'dynamic_image_id is present in lane serialization');
assert_true($arr['dynamic_image_id'] === 42, 'dynamic_image_id matches the set integer value');

// Some basic sanity checks to ensure no regressions
assert_true($arr['department'] === 7, 'department matches');
assert_true($arr['name'] === 'Test Lane', 'name matches');

echo "DepartmentLaneDynamicImageIdTest completed.\n";
