package youngee_talent_service

import (
	"youngmini_server/app/dao"
	"youngmini_server/app/model/youngee_talent_model"
	"youngmini_server/app/utils"

	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
)

func OnPostTalentInfo(r *ghttp.Request) *TalentHttpResult {
	tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
	if err != nil {
		return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
	}
	var infos *youngee_talent_model.TalentSelfInputInfo
	err = r.ParseForm(&infos)
	if err != nil {
		return &TalentHttpResult{Code: -2, Msg: err.Error()}
	}
	infos.IsBindInfo = 1
	_, err = g.DB().Model(dao.YoungeeTalentInfo.Table).Update(infos, "id", tid)
	if err != nil {
		return &TalentHttpResult{Code: -4, Msg: "update failed"}
	}

	return &TalentHttpResult{Code: 0, Msg: "success"}
}

func GetTalentInfo(r *ghttp.Request) *TalentHttpResult {
	tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
	if err != nil {
		return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
	}

	talentInfo := youngee_talent_model.TalentInfo{}
	err = g.DB().Model("youngee_talent_info").WithAll().Where("id", tid).Scan(&talentInfo)

	if err != nil {
		return &TalentHttpResult{Code: -2, Msg: "Get talent info failed"}
	}
	return &TalentHttpResult{Code: 0, Msg: "success", Data: talentInfo}
}
