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

export class SonosConfigFlow implements IConfigFlow<ISonosConfig> {
  public async start(candidateArg: IDiscoveryCandidate, contextArg: IConfigFlowContext): Promise<IConfigFlowStep<ISonosConfig>> {
    void contextArg;
    return {
      kind: 'form',
      title: 'Connect Sonos',
      description: 'Configure the local Sonos player HTTP endpoint discovered by SSDP or mDNS.',
      fields: [
        { name: 'host', label: 'Host', type: 'text', required: true },
        { name: 'port', label: 'Port', type: 'number' },
      ],
      submit: async (valuesArg) => ({
        kind: 'done',
        title: 'Sonos configured',
        config: {
          host: String(valuesArg.host || candidateArg.host || ''),
          port: typeof valuesArg.port === 'number' ? valuesArg.port : candidateArg.port || 1400,
        },
      }),
    };
  }
}
