import { defineRelations } from "drizzle-orm";
import * as schema from "./schema.ts";

export const relations = defineRelations(schema, (r) => ({
    priceHistory: {
        sku: r.one.skus({
            from: r.priceHistory.skuId,
            to: r.skus.skuId,
        }),
    },
    salesHistory: {
        sku: r.one.skus({
            from: r.salesHistory.skuId,
            to: r.skus.skuId,
        }),
    },
    skus: {
        card: r.one.cards({
            from: [r.skus.productId, r.skus.variant],
            to: [r.cards.productId, r.cards.variant],
        }),
        history: r.many.priceHistory(),
        latestSales: r.many.salesHistory(),
        inventories: r.many.inventory(),
    },
    inventory: {
        sku: r.one.skus({
            from: r.inventory.skuId,
            to: r.skus.skuId,
        }),
    },
    cards: {
        prices: r.many.skus(),
        set: r.one.sets({
            from: r.cards.setId,
            to: r.sets.setId,
        }),
        tcgdata: r.one.tcgcards({
            from: r.cards.productId,
            to: r.tcgcards.productId,
        }),
    },
    sets: {
        cards: r.many.cards(),
    },
    tcgcards: {
        cards: r.many.cards(),
    },
}));

