package controller

import (
	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
	"youngee_b_api/app/service"
	"youngee_b_api/app/vo"
)

type BillController struct{}

// 电商带货账单列表
func (f BillController) SelectionBillList(c *gin.Context) {
	param := &vo.SelectionSearchParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	result, err := service.BillService{}.GetBillSelectionTaskList(param)
	if err != nil {
		logrus.Errorf("[SelectionBillList] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	returnSuccess(c, 20000, result)
}

// 电商带货账单支付
func (f BillController) SelectionPay(c *gin.Context) {
	param := &vo.PayParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	err1 := service.BillService{}.PaySelection(param)
	if err1 != nil {
		if err1.Error() == "状态异常" {
			returnError(c, 31000, err1.Error())
			return
		}
		if err1.Error() == "可用余额不足" {
			returnError(c, 32000, err1.Error())
			return
		}
		logrus.Errorf("[SelectionPay] call Show err:%+v\n", err)
		returnError(c, 40000, err1.Error())
		return
	}
	returnSuccess(c, 20000, nil)
}

// 品牌种草账单列表
func (f BillController) ProjectBillList(c *gin.Context) {
	param := &vo.ProjectSearchParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	result, err := service.BillService{}.GetBillProjectTaskList(param)
	if err != nil {
		logrus.Errorf("[ProjectBillList] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	returnSuccess(c, 20000, result)
}

// 品牌种草账单支付
func (f BillController) ProjectPay(c *gin.Context) {
	param := &vo.PayParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	err1 := service.BillService{}.PayProject(param)
	if err1 != nil {
		if err1.Error() == "状态异常" {
			returnError(c, 31000, err1.Error())
			return
		}
		if err1.Error() == "可用余额不足" {
			returnError(c, 32000, err1.Error())
			return
		}
		logrus.Errorf("[ProjectPay] call Show err:%+v\n", err)
		returnError(c, 40000, err1.Error())
		return
	}
	returnSuccess(c, 20000, nil)
}

// 本地生活账单列表
func (f BillController) LocalLifeBillList(c *gin.Context) {
	param := &vo.LocalSearchParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	result, err := service.BillService{}.GetBillLocalLifeTaskList(param)
	if err != nil {
		logrus.Errorf("[LocalLifeBillList] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	returnSuccess(c, 20000, result)
}

// 本地生活账单支付
func (f BillController) LocalLifePay(c *gin.Context) {
	param := &vo.PayParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	err1 := service.BillService{}.PayLocalLife(param)
	if err1 != nil {
		if err1.Error() == "状态异常" {
			returnError(c, 31000, err1.Error())
			return
		}
		if err1.Error() == "可用余额不足" {
			returnError(c, 32000, err1.Error())
			return
		}
		logrus.Errorf("[LocalLifePay] call Show err:%+v\n", err)
		returnError(c, 40000, err1.Error())
		return
	}
	returnSuccess(c, 20000, nil)
}
