import { resolveArticlePage } from "./resolveArticlePage";
import { resolveProductPage } from "./resolveProductPage";

export type SlugResult =
    | ReturnType<typeof resolveArticlePage>
    | ReturnType<typeof resolveProductPage>;

export function findBySlug(slug?: string): SlugResult | null {
    if (!slug || slug.trim() === '') {
        return null;
    }

    // PRODUCT
    const product = resolveProductPage(slug);
    if (product) return product;

    // ARTICLE
    const articler = resolveArticlePage(slug);
    if (articler) return articler;

    // 404
    return null;
}