import { Command, type CommandShape } from "./command"

export const commandsShapes = {
  ls: {
    command: "ls",
    description: "List the contents of a directory",
    args: [
      { name: "path", type: "string", description: "The path to list", named: false },
      {
        name: "all",
        type: "boolean",
        description: "Show hidden files",
        named: true,
        default: false,
      },
      {
        name: "long",
        type: "boolean",
        description: "List in long format",
        named: true,
        default: false,
      },
      {
        name: "short-names",
        type: "boolean",
        description: "Only print file names",
        named: true,
        default: false,
      },
      {
        name: "full-paths",
        type: "boolean",
        description: "Display full paths",
        named: true,
        default: false,
      },
    ],
  },

  cd: {
    command: "cd",
    description: "Change the current working directory",
    args: [{ name: "path", type: "string", description: "The path to change to", named: false }],
  },

  cp: {
    command: "cp",
    description: "Copy files or directories",
    args: [
      { name: "source", type: "string", description: "Source file or directory" },
      { name: "destination", type: "string", description: "Destination path" },
      {
        name: "recursive",
        type: "boolean",
        description: "Copy recursively",
        named: true,
        default: false,
      },
      {
        name: "verbose",
        type: "boolean",
        description: "Verbose output",
        named: true,
        default: false,
      },
    ],
  },

  mv: {
    command: "mv",
    description: "Move files or directories",
    args: [
      { name: "source", type: "string", description: "Source file or directory" },
      { name: "destination", type: "string", description: "Destination path" },
      {
        name: "verbose",
        type: "boolean",
        description: "Verbose output",
        named: true,
        default: false,
      },
    ],
  },

  rm: {
    command: "rm",
    description: "Remove files or directories",
    args: [
      { name: "path", type: "string", description: "Path to remove" },
      {
        name: "recursive",
        type: "boolean",
        description: "Remove recursively",
        named: true,
        default: false,
      },
      { name: "force", type: "boolean", description: "Force removal", named: true, default: false },
      {
        name: "verbose",
        type: "boolean",
        description: "Verbose output",
        named: true,
        default: false,
      },
    ],
  },

  mkdir: {
    command: "mkdir",
    description: "Create directories",
    args: [
      { name: "path", type: "string", description: "Directory path to create" },
      {
        name: "verbose",
        type: "boolean",
        description: "Verbose output",
        named: true,
        default: false,
      },
    ],
  },

  touch: {
    command: "touch",
    description: "Create empty files or update timestamps",
    args: [
      { name: "path", type: "string", description: "File path to touch" },
      {
        name: "access",
        type: "boolean",
        description: "Update access time only",
        named: true,
        default: false,
      },
      {
        name: "modified",
        type: "boolean",
        description: "Update modified time only",
        named: true,
        default: false,
      },
    ],
  },

  // Text operations
  echo: {
    command: "echo",
    description: "Display a string",
    args: [
      { name: "text", type: "string", description: "Text to display" },
      {
        name: "no-newline",
        type: "boolean",
        description: "Don't append newline",
        named: true,
        default: false,
      },
    ],
  },

  cat: {
    command: "cat",
    description: "Display file contents",
    args: [
      { name: "path", type: "string", description: "File to display" },
      {
        name: "numbered",
        type: "boolean",
        description: "Show line numbers",
        named: true,
        default: false,
      },
    ],
  },

  head: {
    command: "head",
    description: "Show first lines of input",
    args: [
      { name: "path", type: "string", description: "File to read from", named: false },
      { name: "lines", type: "number", description: "Number of lines", named: true, default: 10 },
    ],
  },

  tail: {
    command: "tail",
    description: "Show last lines of input",
    args: [
      { name: "path", type: "string", description: "File to read from", named: false },
      { name: "lines", type: "number", description: "Number of lines", named: true, default: 10 },
      {
        name: "follow",
        type: "boolean",
        description: "Follow file changes",
        named: true,
        default: false,
      },
    ],
  },

  grep: {
    command: "grep",
    description: "Search for patterns in text",
    args: [
      { name: "pattern", type: "string", description: "Pattern to search for" },
      {
        name: "ignore-case",
        type: "boolean",
        description: "Case insensitive search",
        named: true,
        default: false,
      },
      {
        name: "invert-match",
        type: "boolean",
        description: "Invert match",
        named: true,
        default: false,
      },
      {
        name: "line-number",
        type: "boolean",
        description: "Show line numbers",
        named: true,
        default: false,
      },
    ],
  },

  sort: {
    command: "sort",
    description: "Sort input",
    args: [
      {
        name: "reverse",
        type: "boolean",
        description: "Sort in reverse order",
        named: true,
        default: false,
      },
      {
        name: "ignore-case",
        type: "boolean",
        description: "Case insensitive sort",
        named: true,
        default: false,
      },
      {
        name: "numeric",
        type: "boolean",
        description: "Numeric sort",
        named: true,
        default: false,
      },
    ],
  },

  uniq: {
    command: "uniq",
    description: "Filter out repeated lines",
    args: [
      {
        name: "count",
        type: "boolean",
        description: "Show count of occurrences",
        named: true,
        default: false,
      },
      {
        name: "repeated",
        type: "boolean",
        description: "Show only repeated lines",
        named: true,
        default: false,
      },
      {
        name: "unique",
        type: "boolean",
        description: "Show only unique lines",
        named: true,
        default: false,
      },
    ],
  },

  // Data manipulation
  select: {
    command: "select",
    description: "Select specific columns from data",
    args: [{ name: "columns", type: "string", description: "Columns to select" }],
  },

  where: {
    command: "where",
    description: "Filter data based on conditions",
    args: [{ name: "condition", type: "string", description: "Filter condition" }],
  },

  group_by: {
    command: "group-by",
    description: "Group data by column values",
    args: [{ name: "column", type: "string", description: "Column to group by" }],
  },

  // // Network operations
  // http_get: {
  //   command: "http get",
  //   description: "Fetch data from a URL via GET request",
  //   args: [
  //     { name: "url", type: "string", description: "URL to fetch" },
  //     { name: "headers", type: "string", description: "HTTP headers", named: true, default: "" },
  //     {
  //       name: "raw",
  //       type: "boolean",
  //       description: "Return raw response",
  //       named: true,
  //       default: false,
  //     },
  //     {
  //       name: "insecure",
  //       type: "boolean",
  //       description: "Allow insecure connections",
  //       named: true,
  //       default: false,
  //     },
  //   ],
  // },

  // http_post: {
  //   command: "http post",
  //   description: "Send data via POST request",
  //   args: [
  //     { name: "url", type: "string", description: "URL to post to" },
  //     { name: "data", type: "string", description: "Data to send", named: false },
  //     {
  //       name: "content-type",
  //       type: "string",
  //       description: "Content type",
  //       named: true,
  //       default: "application/json",
  //     },
  //     { name: "headers", type: "string", description: "HTTP headers", named: true, default: "" },
  //   ],
  // },

  // System operations
  ps: {
    command: "ps",
    description: "List running processes",
    args: [
      {
        name: "long",
        type: "boolean",
        description: "Show detailed information",
        named: true,
        default: false,
      },
    ],
  },

  sys: {
    command: "sys",
    description: "Show system information",
    args: [],
  },

  which: {
    command: "which",
    description: "Find the location of a command",
    args: [
      { name: "command", type: "string", description: "Command to locate" },
      {
        name: "all",
        type: "boolean",
        description: "Show all matches",
        named: true,
        default: false,
      },
    ],
  },

  // // Conversion operations
  // to_json: {
  //   command: "to json",
  //   description: "Convert data to JSON",
  //   args: [
  //     { name: "indent", type: "number", description: "JSON indentation", named: true, default: 2 },
  //     { name: "raw", type: "boolean", description: "Output raw JSON", named: true, default: false },
  //   ],
  // },

  // from_json: {
  //   command: "from json",
  //   description: "Parse JSON data",
  //   args: [
  //     {
  //       name: "objects",
  //       type: "boolean",
  //       description: "Parse multiple objects",
  //       named: true,
  //       default: false,
  //     },
  //   ],
  // },

  // to_csv: {
  //   command: "to csv",
  //   description: "Convert data to CSV",
  //   args: [
  //     {
  //       name: "separator",
  //       type: "string",
  //       description: "Field separator",
  //       named: true,
  //       default: ",",
  //     },
  //     {
  //       name: "no-headers",
  //       type: "boolean",
  //       description: "Don't include headers",
  //       named: true,
  //       default: false,
  //     },
  //   ],
  // },

  // from_csv: {
  //   command: "from csv",
  //   description: "Parse CSV data",
  //   args: [
  //     {
  //       name: "separator",
  //       type: "string",
  //       description: "Field separator",
  //       named: true,
  //       default: ",",
  //     },
  //     {
  //       name: "no-headers",
  //       type: "boolean",
  //       description: "No header row",
  //       named: true,
  //       default: false,
  //     },
  //   ],
  // },
} as const satisfies Record<string, CommandShape>

export const commands: Command[] = Object.values(commandsShapes).map((shape) => new Command(shape))
