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

export class WolfSmartsetConfigFlow implements IConfigFlow<IWolfSmartsetConfig> {
  public async start(candidateArg: IDiscoveryCandidate, contextArg: IConfigFlowContext): Promise<IConfigFlowStep<IWolfSmartsetConfig>> {
    void contextArg;
    return {
      kind: 'form',
      title: 'Connect Wolf Smartset',
      description: 'Use a local host when available, otherwise configure cloud credentials.',
      fields: [
        { name: 'authMode', label: 'Auth mode', type: 'select', required: true, options: [
          { label: 'Cloud', value: 'cloud' },
          { label: 'Local', value: 'local' },
        ] },
        { name: 'host', label: 'Local host', type: 'text' },
        { name: 'username', label: 'Username', type: 'text' },
        { name: 'password', label: 'Password', type: 'password' },
      ],
      submit: async (valuesArg) => ({
        kind: 'done',
        title: 'Wolf Smartset configured',
        config: {
          authMode: valuesArg.authMode === 'local' ? 'local' : 'cloud',
          host: String(valuesArg.host || candidateArg.host || ''),
          username: String(valuesArg.username || ''),
          password: String(valuesArg.password || ''),
        },
      }),
    };
  }
}
