package dao

import (
	"database/sql"
	"github.com/sirupsen/logrus"
	"youngee_b_api/app/entity"
)

type TalentInfoDao struct{}

func (d TalentInfoDao) SelectTalentPhone(talentId string) (*string, error) {
	var talentInfo *entity.YoungeeTalentInfo
	err := Db.Model(entity.YoungeeTalentInfo{}).Select("talent_phone_number").Where("id = ?", talentId).Find(&talentInfo).Error
	if err != nil {
		logrus.Errorf("[SelectTalentInfo] error query, err:%+v", err)
		return nil, err
	}
	return &talentInfo.TalentPhoneNumber, nil
}

func (d TalentInfoDao) SelectTalentInfo(talentId string) (*entity.YoungeeTalentInfo, error) {
	var talentInfo *entity.YoungeeTalentInfo
	err := Db.Model(&entity.YoungeeTalentInfo{}).Where("id = ?", talentId).Find(&talentInfo).Error
	if err != nil {
		if err.Error() == sql.ErrNoRows.Error() {
			return nil, nil
		}
		logrus.Errorf("[SelectTalentInfo] error query, err:%+v", err)
		return nil, err
	}
	return talentInfo, nil
}

// 获取达人内容类型
func (d TalentInfoDao) GetTalentCategory() ([]entity.TalentCategory, error) {
	var talentCategory []entity.TalentCategory
	err := Db.Model(&entity.TalentCategory{}).Find(&talentCategory).Error
	return talentCategory, err
}
