import { pluralize } from "../util/pluralize";

export interface PaymentMethodItem {
  method: string;
  count: number;
}

export interface PurchaseCountItem {
  date: string;
  count: number;
}

export interface PurchaseAmountItem {
  site_code: string;
  amount: string;
  currency: string;
}

export const filterPresets = [
  { label: "Today", value: "today" },
  { label: "Yesterday", value: "yesterday" },
  { label: "Last 7 days", value: "last_7_days" },
  { label: "Last 30 days", value: "last_30_days" },
  { label: "This week", value: "this_week" },
  { label: "Last week", value: "last_week" },
  { label: "This month", value: "this_month" },
  { label: "Last month", value: "last_month" },
  { label: "This year", value: "this_year" },
  { label: "Last year", value: "last_year" },
  { label: "Custom", value: "custom" },
] as const;

export type FilterPreset = (typeof filterPresets)[number]["value"];

export type Granularity = "day" | "week" | "month" | "quarter" | "year";

export function isGranularity(granularity: unknown): granularity is Granularity {
  return (
    typeof granularity === "string" &&
    ["day", "week", "month", "quarter", "year"].includes(granularity)
  );
}

export function pluralizeGranularity(count: number, granularity: Granularity) {
  switch (granularity) {
    case "day":
      return pluralize(count, "day", "days", "no days");
    case "week":
      return pluralize(count, "week", "weeks", "no weeks");
    case "month":
      return pluralize(count, "month", "months", "no months");
    case "quarter":
      return pluralize(count, "quarter", "quarters", "no quarters");
    case "year":
      return pluralize(count, "year", "years", "no years");
  }
}

export const granularityLabel = (granularity: Granularity) => {
  switch (granularity) {
    case "day":
      return "Daily";
    case "week":
      return "Weekly";
    case "month":
      return "Monthly";
    case "year":
      return "Yearly";
    case "quarter":
      return "Quarterly";
  }
};
