// Gateway MongoDB 初始化（僅在 data volume 首次建立時執行）
// 與 internal/model/notification/repository/* Index20260520001UP 對齊
// 既有 volume 請執行：make mongo-index

db = db.getSiblingDB('gateway');

print('Creating indexes on notifications...');

db.notifications.createIndex(
  { tenant_id: 1, kind: 1, idempotency_key: 1 },
  { unique: true, name: 'idx_notifications_tenant_kind_idempotency' }
);

db.notifications.createIndex(
  { tenant_id: 1, uid: 1, occurred_at: -1 },
  { name: 'idx_notifications_tenant_uid_occurred' }
);

db.notifications.createIndex(
  { status: 1, attempts: 1, occurred_at: 1 },
  { name: 'idx_notifications_status_attempts_occurred' }
);

print('Creating indexes on notification_dlq...');

db.notification_dlq.createIndex(
  { tenant_id: 1, occurred_at: -1 },
  { name: 'idx_notification_dlq_tenant_occurred' }
);

print('Gateway Mongo init done.');
