import { expect, tap } from '@git.zone/tstest/tapbundle';
import { ManualMqttIntegration, manualMqttProfile } from '../../ts/integrations/manual_mqtt/index.js';

tap.test('documents Manual MQTT broker-semantics blocker and avoids fake alarm state changes', async () => {
  const metadata = manualMqttProfile.metadata as {
    runtime: { blocker: string; controls: boolean };
    localApi: { explicitUnsupported: string[] };
  };

  expect(manualMqttProfile.status).toEqual('read-only-runtime');
  expect(metadata.runtime.controls).toBeFalse();
  expect(metadata.runtime.blocker.includes('MQTT broker subscribe/publish semantics')).toBeTrue();
  expect(metadata.localApi.explicitUnsupported.some((itemArg) => itemArg.includes('mqtt.async_subscribe'))).toBeTrue();

  const runtime = await new ManualMqttIntegration().setup({ name: 'HA Alarm' }, {});
  const result = await runtime.callService?.({ domain: 'manual_mqtt', service: 'turn_on', target: {} });
  expect(result?.success).toBeFalse();
  expect(result?.error?.includes('requires an injected client.execute() or commandExecutor')).toBeTrue();
  await runtime.destroy();
});

export default tap.start();
