package controllers

import (
	"nearle/db"
	"nearle/models"
	"net/http"
	"strconv"

	"github.com/gofiber/fiber/v2"
)

func CreatePaymentRequest(c *fiber.Ctx) error {

	var data models.Paymentrequests

	if err := c.BodyParser(&data); err != nil {
		return err
	}

	err := db.DB.Create(&data).Error

	if err != nil {
		return c.JSON(fiber.Map{
			"code":    http.StatusConflict,
			"message": err.Error(),
			"status":  false,
		})

	}

	return c.JSON(fiber.Map{
		"code":    http.StatusCreated,
		"message": "Success",
		"status":  true,
	})
}

func GetPaymentRequests(c *fiber.Ctx) error {

	var data []models.RequestInfo

	pid, _ := strconv.Atoi(c.Query("partnerid"))
	status, _ := strconv.Atoi(c.Query("status"))

	q1 := "select * from paymentrequests where partnerid=? and status=?"
	db.DB.Raw(q1, pid, status).Find(&data)

	return c.JSON(fiber.Map{
		"code":    http.StatusOK,
		"message": "Success",
		"status":  true,
		"details": data,
	})

}
