import { NextRequest, NextResponse } from 'next/server'
import prisma from '@/lib/prisma'
import { checkCashifyStatus } from '@/lib/cashify'

export async function POST(req: NextRequest) {
  try {
    const { transactionId } = await req.json()
    if (!transactionId) {
      return NextResponse.json({ error: 'transactionId diperlukan' }, { status: 400 })
    }

    const status = await checkCashifyStatus(transactionId)
    return NextResponse.json({ status: status.status, expiredAt: status.expiredAt })
  } catch (error) {
    console.error('[CHECK STATUS]', error)
    return NextResponse.json({ error: 'Gagal mengecek status pembayaran' }, { status: 500 })
  }
}
