import {
  USER_LOCAL_COMMAND_ARGUMENT_HINT,
  USER_LOCAL_COMMAND_DESCRIPTION,
  executeUserLocalCommand,
} from './user-local-command.js';

import type { ICommandModule, ISystemCommand } from '@robota-sdk/agent-framework';
import type { ICommand, ICommandSource } from '@robota-sdk/agent-interface-transport';

export function createUserLocalCommandEntry(): ICommand {
  return {
    name: 'user-local',
    displayName: 'User Config',
    description: USER_LOCAL_COMMAND_DESCRIPTION,
    source: 'user-local',
    argumentHint: USER_LOCAL_COMMAND_ARGUMENT_HINT,
    modelInvocable: false,
    safety: 'read-only',
    subcommands: [
      {
        name: 'storage',
        description: 'Inspect user-local storage categories',
        source: 'user-local',
      },
      {
        name: 'memory',
        description: 'Inspect and manage user-local memory items',
        source: 'user-local',
      },
    ],
  };
}

function createUserLocalSystemCommand(): ISystemCommand {
  const entry = createUserLocalCommandEntry();
  return {
    name: entry.name,
    displayName: entry.displayName,
    description: entry.description,
    requiresPermission: false,
    userInvocable: true,
    modelInvocable: false,
    argumentHint: entry.argumentHint,
    safety: entry.safety,
    subcommands: entry.subcommands,
    execute: executeUserLocalCommand,
  };
}

export class UserLocalCommandSource implements ICommandSource {
  readonly name = 'user-local';

  getCommands(): ICommand[] {
    return [createUserLocalCommandEntry()];
  }
}

export function createUserLocalCommandModule(): ICommandModule {
  return {
    name: 'agent-command-user-local',
    commandSources: [new UserLocalCommandSource()],
    systemCommands: [createUserLocalSystemCommand()],
  };
}
