import db from "../db.server"; import { locationLimitFor, type Tier } from "../lib/billing-plans"; export type { Tier }; export { tierAtLeast, tierFromPlanName, locationLimitFor, LOCATION_LIMITS, PLAN_PRICING } from "../lib/billing-plans"; export async function getShopTier(shopDomain: string): Promise { const shop = await db.shop.findUnique({ where: { shopDomain }, select: { tier: true } }); return (shop?.tier as Tier | undefined) ?? "free"; } export async function setShopTier(shopDomain: string, tier: Tier): Promise { await db.shop.upsert({ where: { shopDomain }, create: { shopDomain, tier }, update: { tier }, }); } export async function countLocations(shopDomain: string): Promise { return db.location.count({ where: { shopDomain } }); } export async function canAddLocation(shopDomain: string): Promise { const tier = await getShopTier(shopDomain); const limit = locationLimitFor(tier); if (limit === null) return true; return (await countLocations(shopDomain)) < limit; }