import type { IConfigFlow, IConfigFlowContext, IConfigFlowStep, IDiscoveryCandidate } from '../../core/types.js';
import type { IRokuConfig } from './roku.types.js';

export class RokuConfigFlow implements IConfigFlow<IRokuConfig> {
  public async start(candidateArg: IDiscoveryCandidate, contextArg: IConfigFlowContext): Promise<IConfigFlowStep<IRokuConfig>> {
    void contextArg;
    return {
      kind: 'form',
      title: 'Connect Roku',
      description: 'Configure the local Roku External Control Protocol endpoint.',
      fields: [
        { name: 'host', label: 'Host', type: 'text', required: true },
        { name: 'port', label: 'Port', type: 'number' },
      ],
      submit: async (valuesArg) => ({
        kind: 'done',
        title: 'Roku configured',
        config: {
          host: String(valuesArg.host || candidateArg.host || ''),
          port: typeof valuesArg.port === 'number' ? valuesArg.port : candidateArg.port || 8060,
        },
      }),
    };
  }
}
