<?php

namespace classes {
    class db {}

    class object_property
    {
        public function __construct(...$args) {}
        public function value() { return null; }
        public function set($v) {}
    }
}

namespace traits {
    trait db_object_t {}
}

namespace {
    app_require('objects/department_selfserve_tasks_o.php');
    app_require('modules/selfserve/helpers/selfserve_lane_services.php');
}

namespace {
    use modules\selfserve\helpers\selfserve_lane_services;
    use objects\department_selfserve_tasks_o;

    it('normalizes button arrays, json and csv inputs', function (): void {
        expect(department_selfserve_tasks_o::normalizeButtonsInput([1, '2', 3]))->toBe([1, 2, 3]);
        expect(department_selfserve_tasks_o::normalizeButtonsInput('[4,5,5,0]'))->toBe([4, 5, 0]);
        expect(department_selfserve_tasks_o::normalizeButtonsInput('6, 7 ,8'))->toBe([6, 7, 8]);
    });

    it('rejects invalid button inputs', function (): void {
        department_selfserve_tasks_o::normalizeButtonsInput('["a", 2]');
    })->throws(\Exception::class);

    it('normalizes vehicle type values and null semantics', function (): void {
        expect(department_selfserve_tasks_o::normalizeVehicleTypeInput(3))->toBe(3);
        expect(department_selfserve_tasks_o::normalizeVehicleTypeInput('4'))->toBe(4);
        expect(department_selfserve_tasks_o::normalizeVehicleTypeInput(' 5 '))->toBe(5);
        expect(department_selfserve_tasks_o::normalizeVehicleTypeInput(null))->toBeNull();
        expect(department_selfserve_tasks_o::normalizeVehicleTypeInput(''))->toBeNull();
    });

    it('rejects invalid vehicle type values', function (): void {
        department_selfserve_tasks_o::normalizeVehicleTypeInput(-1);
    })->throws(\Exception::class);

    it('rejects non-numeric vehicle type strings', function (): void {
        department_selfserve_tasks_o::normalizeVehicleTypeInput('abc');
    })->throws(\Exception::class);

    it('keeps lane service enum contract for MACHINE', function (): void {
        $names = array_map(static fn(selfserve_lane_services $case): string => $case->name, selfserve_lane_services::cases());
        expect($names)->toContain('MACHINE');
    });
}

