package pack

import (
	"youngee_b_api/model/http_model"

	"github.com/tidwall/gjson"

	"github.com/issue9/conv"
)

func MGormTaskTerminatedInfoListToHttpTaskTerminatedPreviewList(gormTaskTerminatedInfos []*http_model.TaskTerminatedInfo) []*http_model.TaskTerminatedPreview {
	var httpProjectPreviews []*http_model.TaskTerminatedPreview
	for _, gormTaskTerminatedInfo := range gormTaskTerminatedInfos {
		httpTaskTerminatedPreview := MGormTaskTerminatedInfoToHttpTaskTerminatedPreview(gormTaskTerminatedInfo)
		httpProjectPreviews = append(httpProjectPreviews, httpTaskTerminatedPreview)
	}
	return httpProjectPreviews
}

func MGormTaskTerminatedInfoToHttpTaskTerminatedPreview(TaskTerminatedInfo *http_model.TaskTerminatedInfo) *http_model.TaskTerminatedPreview {
	return &http_model.TaskTerminatedPreview{
		TaskID:            conv.MustString(TaskTerminatedInfo.TaskID),
		PlatformNickname:  conv.MustString(TaskTerminatedInfo.PlatformNickname),
		FansCount:         conv.MustString(TaskTerminatedInfo.FansCount),
		RecruitStrategyID: conv.MustString(TaskTerminatedInfo.RecruitStrategyID),
		StrategyID:        conv.MustString(TaskTerminatedInfo.StrategyID),
		AllPayment:        TaskTerminatedInfo.AllPayment,
		RealPayment:       TaskTerminatedInfo.RealPayment,
		BreakType:         conv.MustString(TaskTerminatedInfo.BreakType),
		HandleAt: conv.MustString(TaskTerminatedInfo.HandleAt),
	}
}

func TaskTerminatedToTaskInfo(TaskTerminateds []*http_model.TaskTerminated) []*http_model.TaskTerminatedInfo {
	var TaskTerminatedInfos []*http_model.TaskTerminatedInfo
	for _, TaskTerminated := range TaskTerminateds {
		TaskTerminated := GetTerminatedInfoStruct(TaskTerminated)
		TaskTerminatedInfos = append(TaskTerminatedInfos, TaskTerminated)
	}
	return TaskTerminatedInfos
}

func GetTerminatedInfoStruct(TaskTerminated *http_model.TaskTerminated) *http_model.TaskTerminatedInfo {
	TalentPlatformInfoSnap := TaskTerminated.Talent.TalentPlatformInfoSnap
	return &http_model.TaskTerminatedInfo{
		TaskID:           TaskTerminated.Talent.TaskID,
		PlatformNickname: conv.MustString(gjson.Get(TalentPlatformInfoSnap, "platform_nickname")),
		FansCount:        conv.MustString(gjson.Get(TalentPlatformInfoSnap, "fans_count")),
		StrategyID:       TaskTerminated.Talent.StrategyID,
		AllPayment:       TaskTerminated.Talent.AllPayment,
		RealPayment:      TaskTerminated.Talent.RealPayment,
		BreakType:        TaskTerminated.Default.BreakType,
		HandleAt:         conv.MustString(TaskTerminated.Default.HandleAt, "")[:19],
	}
}
