import { SimpleLocalClient, type IServiceCallRequest, type IServiceCallResult } from '../../core/index.js';
import type { IOrviboConfig } from './orvibo.types.js';
import { orviboProfile } from './orvibo.types.js';

export class OrviboClient extends SimpleLocalClient<IOrviboConfig> {
  constructor(private readonly configArg: IOrviboConfig) {
    super(orviboProfile, configArg);
  }

  public async execute(requestArg: IServiceCallRequest): Promise<IServiceCallResult> {
    if (this.configArg.client?.execute || this.configArg.commandExecutor) {
      return super.execute(requestArg);
    }

    return {
      success: false,
      error: `Orvibo service ${requestArg.domain}.${requestArg.service} is not implemented natively: Home Assistant uses orvibo==1.1.2 over a UDP-only binary protocol on port 10000 for discovery, subscription, polling, and control. Provide an injected client.execute() or commandExecutor for live Orvibo writes.`,
    };
  }
}
