import { postgresConnection } from "db";
import type { NextApiRequest, NextApiResponse } from "next";
import { IInventoryItem } from "typings";
import {
  calculateRemainingTime,
} from "../../../../../utils/helpers";

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {
  try {
    if (req.method === "POST") {
      const { userId } = req.query;
      const { stakingEventId } = req.body;

      try {
        const db = postgresConnection;
        const result = await db.query("SELECT * FROM claim($1, $2)", [userId, stakingEventId]);

        // console.log(result.rows[0].claim);
        return res.status(200).json({claimEventId: result.rows[0].claim});
      } catch (error) {
        return res.status(400).json({error: error.message});
      }
    }
  } catch (error) {
    res.status(500).json(error);
  }
}
