/**
 * درگاه شبیه‌ساز برای توسعه و تست بدون اینترنت (در production غیرفعال است).
 * کاربر به صفحه /payment/mock هدایت می‌شود و پرداخت موفق یا ناموفق را انتخاب می‌کند.
 */
import { randomToken } from "@/lib/crypto";
import type { PaymentGateway } from "./gateway";

export const mockGateway: PaymentGateway = {
  id: "mock",
  async request({ callbackUrl, amountRial }) {
    const authority = `MOCK-${randomToken(12)}`;
    const q = new URLSearchParams({ authority, callback: callbackUrl, amount: String(amountRial) });
    return { authority, redirectUrl: `/payment/mock?${q}` };
  },
  parseCallback(params) {
    return { authority: params.get("Authority"), ok: params.get("Status") === "OK" };
  },
  async verify({ authority }) {
    return { ok: true, refId: `MOCK-${authority.slice(-6)}` };
  },
};
