/**
 * Cron: Sold-Out Gold Expire - runs every hour.
 *
 * Clears deals.sold_out_gold_expires_at for deals whose gold shimmer window
 * has passed. This nullifies the gold highlight effect on the sold-out badge.
 * (The gold shimmer lasts 5 hours after a deal sells out - see deals.markSoldOut.)
 */

import { createDbService } from '@/server/services/db.js';
import { withSentry } from '@/server/observability/with-sentry';
import { expireSoldOutGold } from '../db/queries/cron-boundary.js';
import type { CronEnv } from './deal-expiry.js';

export const runSoldOutGoldExpire = withSentry(
  async function runSoldOutGoldExpire(env: CronEnv): Promise<void> {
    const db = env.db ?? createDbService({ DATABASE_URL: env.DATABASE_URL });
    const now = new Date();

    await expireSoldOutGold(db, now);
  },
  { name: 'cron.sold-out-gold-expire', kind: 'cron' },
);
