import type { VehicleRealtimeRow } from '../../api/types';
import { describe, expect, it } from 'vitest';
import { formatNumber, statusLabel, vehicleStatus } from './monitor';

function vehicle(overrides: Partial<VehicleRealtimeRow> = {}): VehicleRealtimeRow {
  return {
    vin: 'LTEST000000000001',
    plate: '粤A00001',
    phone: '',
    oem: '',
    protocols: ['JT808'],
    sourceStatus: [],
    sourceCount: 1,
    onlineSourceCount: 1,
    online: true,
    bindingStatus: 'bound',
    primaryProtocol: 'JT808',
    longitude: 113.2,
    latitude: 23.1,
    speedKmh: 0,
    socPercent: 80,
    totalMileageKm: 10,
    lastSeen: '2026-07-14 01:00:00',
    ...overrides
  };
}

describe('monitor domain', () => {
  it('keeps online, motion and unknown status semantics separate', () => {
    expect(vehicleStatus(vehicle({ online: false }))).toBe('offline');
    expect(vehicleStatus(vehicle({ speedKmh: 32 }))).toBe('driving');
    expect(vehicleStatus(vehicle({ speedKmh: 0 }))).toBe('idle');
    expect(vehicleStatus(vehicle({ lastSeen: '' }))).toBe('unknown');
  });

  it('formats dense monitor values consistently', () => {
    expect(formatNumber(12560)).toBe('12,560');
    expect(statusLabel('driving')).toBe('行驶');
  });
});
