package v1

import (
	"dsbqj-admin/app/service"
	"dsbqj-admin/pkg/app"
	"dsbqj-admin/pkg/e"
	"github.com/gin-gonic/gin"
	"net/http"
)

func Open(c *gin.Context) {
	var appG = app.Gin{C: c}
	service := service.SubscribeOpenService{}
	if err := c.ShouldBind(&service); err == nil {
		if err := service.Open(); err != nil {
			appG.Response(http.StatusOK, e.INVALID_PARAMS, err.Error())
		} else {
			appG.Response(http.StatusOK, e.SUCCESS, nil)
		}
	} else {
		appG.Response(http.StatusOK, e.INVALID_PARAMS, err.Error())
	}
}

func Close(c *gin.Context) {
	var appG = app.Gin{C: c}
	service := service.SubscribeCloseService{}
	if err := c.ShouldBind(&service); err == nil {
		if err := service.Close(); err != nil {
			appG.Response(http.StatusOK, e.INVALID_PARAMS, err.Error())
		} else {
			appG.Response(http.StatusOK, e.SUCCESS, nil)
		}
	} else {
		appG.Response(http.StatusOK, e.INVALID_PARAMS, err.Error())
	}
}

func Check(c *gin.Context) {
	var appG = app.Gin{C: c}
	service := service.SubscribeCheckService{}
	if err := c.ShouldBind(&service); err == nil {
		if err := service.Check(); err != nil {
			appG.Response(http.StatusOK, e.INVALID_PARAMS, err.Error())
		} else {
			appG.Response(http.StatusOK, e.SUCCESS, nil)
		}
	} else {
		appG.Response(http.StatusOK, e.INVALID_PARAMS, err.Error())
	}
}

func Send(c *gin.Context) {
	var appG = app.Gin{C: c}
	service := service.SubscribeSendService{}
	if err := c.ShouldBind(&service); err == nil {
		if err := service.Send(); err != nil {
			appG.Response(http.StatusOK, e.INVALID_PARAMS, err.Error())
		} else {
			appG.Response(http.StatusOK, e.SUCCESS, nil)
		}
	} else {
		appG.Response(http.StatusOK, e.INVALID_PARAMS, err.Error())
	}
}

func Task(c *gin.Context) {
	var appG = app.Gin{C: c}
	service := service.SubscribeTaskService{}
	if err := c.ShouldBind(&service); err == nil {
		if err := service.Task(); err != nil {
			appG.Response(http.StatusOK, e.INVALID_PARAMS, err.Error())
		} else {
			appG.Response(http.StatusOK, e.SUCCESS, nil)
		}
	} else {
		appG.Response(http.StatusOK, e.INVALID_PARAMS, err.Error())
	}
}
