import { Command } from "commander";
import { fetchEvents, saveEvents } from "../controllers/event";

export const eventCommand = new Command("event");

eventCommand
  .command("sync")
  .option("--cursor <string>", "Cursor to start fetching from")
  .option("-t, --types <items...>", "Only fetch events of these types")
  .option(
    "--start <string>",
    "Only fetch events starting from a specific timestamp"
  )
  .option("--end <string>", "Only fetch events before a specific timestamp")
  .description("Fetch your ozone events and store it in the local database")
  .action(
    async (options: {
      start?: string;
      end?: string;
      cursor?: string;
      types?: string[];
    }) => {
      const subjects = await fetchEvents({
        cursor: options.cursor,
        types: options.types,
        createdAfter: options.start,
        createdBefore: options.end,
      });
      await saveEvents(subjects);
    }
  );
