import type { IntegrationRegistry } from '../core/index.js';

export const commandSetup = async (registryArg: IntegrationRegistry, domainArg: string) => {
  const integration = registryArg.get(domainArg) as any;
  if (!integration) {
    throw new Error(`Integration not found: ${domainArg}`);
  }
  if (!integration.configFlow) {
    return {
      domain: domainArg,
      status: 'no-config-flow',
    };
  }
  const step = await integration.configFlow.start(
    {
      source: 'manual',
      integrationDomain: domainArg,
      id: `${domainArg}:manual`,
    },
    {}
  );
  return {
    domain: domainArg,
    step: {
      kind: step.kind,
      title: step.title,
      description: step.description,
      fields: step.fields,
      error: step.error,
    },
  };
};
