package backstage_service

import (
	"github.com/gogf/gf/frame/g"
	"youngmini_server/app/model/backstage_model"
)

var Expert = serviceExpert{}

type serviceExpert struct {
}

func (s *serviceExpert) FindAllExpert(expert *backstage_model.ExpertFind) ([]*backstage_model.ExpertRequest, int, error) {
	var res []*backstage_model.ExpertRequest
	g.DB().SetDebug(true)
	err := g.DB().Model("talent_info").OmitEmpty().Where(expert.Expert).
		Page(expert.IndexPage, expert.PageSize).OrderDesc("id").Scan(&res)
	if err != nil {
		return nil, 0, err
	}
	num, err := g.DB().Model("talent_info").OmitEmpty().Where(expert.Expert).
		Page(expert.IndexPage, expert.PageSize).OrderDesc("id").Count()
	if err != nil {
		return nil, 0, err
	}
	return res, num, nil
}

func (s *serviceExpert) FindAddressById(address *backstage_model.TalentDeliveryAddress) ([]*backstage_model.TalentDeliveryAddress, error) {
	var res []*backstage_model.TalentDeliveryAddress
	g.DB().SetDebug(true)
	err := g.DB().Model("talent_delivery_address").OmitEmpty().Where(address).Scan(&res)
	if err != nil {
		return nil, err
	}
	return res, nil
}

func (s *serviceExpert) ChangeStatus(status *backstage_model.ChangeBlack) error {
	g.DB().SetDebug(true)
	_, err := g.DB().Model("talent_info").Data(g.Map{"in_blacklist": status.Status}).Where("id", status.Id).Update()
	if err != nil {
		return err
	}
	return nil
}
