/**
 * The period Overview is scoped to, as URL state.
 *
 * One home for the four values and for the rule that turns whatever the URL
 * carried into one of them: the route validates with it and the picker offers
 * exactly the same list, so a hand-typed `?period=90d` becomes the default
 * instead of reaching the API as a parameter it answers 400 to.
 */

import type { Period } from "@/lib/types";

export const PERIODS = ["1h", "24h", "7d", "30d"] as const satisfies readonly Period[];

export const DEFAULT_PERIOD: Period = "24h";

/**
 * Undefined rather than the default for anything that is not one of the four,
 * so an absent parameter and a nonsense one both leave a clean URL. The default
 * is applied where the period is read, not written back into the address bar.
 */
export function parsePeriod(value: unknown): Period | undefined {
	return PERIODS.find((period) => period === value);
}
