package backstage_api

import (
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
	"github.com/gogf/gf/util/gconv"
	"net/http"
	"youngmini_server/app/model/backstage_model"
	"youngmini_server/app/service/backstage_service"
	"youngmini_server/library/response"
)

var Account = accountApi{}

type accountApi struct {
}

// FindAll 查询所有
func (account *accountApi) FindAll(r *ghttp.Request) {
	var apiReq *backstage_model.AccountFindAll
	if err := r.ParseForm(&apiReq); err != nil {
		response.JsonExit(r, http.StatusBadRequest, err.Error())
	}
	result, num, err := backstage_service.Account.FindAll(apiReq)
	if err != nil {
		response.JsonExit(r, http.StatusInternalServerError, err.Error())
	}
	response.JsonExit(r, http.StatusOK, "数据返回成功", g.Map{
		"result": result, "num": num,
	})
}

// FindTimeRange 带有时间范围查询的请求
func (account *accountApi) FindTimeRange(r *ghttp.Request) {
	var apiReq *backstage_model.RequestAccount
	if err := r.ParseForm(&apiReq); err != nil {
		response.JsonExit(r, http.StatusBadRequest, err.Error())
	}
	res, num, err := backstage_service.Account.FindTimeRange(apiReq)
	if err != nil {
		response.JsonExit(r, http.StatusInternalServerError, err.Error())
	}
	var result []*backstage_model.AccountManagement
	err = gconv.Structs(res, &result)
	if err != nil {
		response.JsonExit(r, http.StatusInternalServerError, err.Error())
	}
	response.JsonExit(r, http.StatusOK, "数据返回成功", g.Map{
		"result": result, "num": num,
	})
}

// ChangeListStatus 批量审核成功或失败
func (account *accountApi) ChangeListStatus(r *ghttp.Request) {
	var apiReq *backstage_model.RequestAccountList
	if err := r.ParseForm(&apiReq); err != nil {
		response.JsonExit(r, http.StatusBadRequest, err.Error())
	}
	err := backstage_service.Account.ChangeListStatus(apiReq)
	if err != nil {
		response.JsonExit(r, http.StatusInternalServerError, err.Error())
	}
	response.JsonExit(r, http.StatusOK, "0")
}

// 根据达人ID 查询单个达人信息
