package threads_account

import (
	cfentity "haixun-backend/internal/model/content_formula/domain/entity"
	cfdom "haixun-backend/internal/model/content_formula/domain/usecase"
	"haixun-backend/internal/types"
)

func toContentFormulaData(item cfdom.FormulaSummary) types.ContentFormulaData {
	var metrics *types.ContentFormulaSourceMetricsData
	if item.SourceMetrics != nil {
		metrics = &types.ContentFormulaSourceMetricsData{
			LikeCount:   item.SourceMetrics.LikeCount,
			ReplyCount:  item.SourceMetrics.ReplyCount,
			Views:       item.SourceMetrics.Views,
			RepostCount: item.SourceMetrics.RepostCount,
			QuoteCount:  item.SourceMetrics.QuoteCount,
			Shares:      item.SourceMetrics.Shares,
		}
	}
	return types.ContentFormulaData{
		ID:              item.ID,
		AccountID:       item.AccountID,
		Label:           item.Label,
		SourceType:      item.SourceType,
		SourceRef:       item.SourceRef,
		SourcePostText:  item.SourcePostText,
		SourceAuthor:    item.SourceAuthor,
		SourcePermalink: item.SourcePermalink,
		SourceMetrics:   metrics,
		Summary:         item.Summary,
		Wins:            item.Wins,
		Improvements:    item.Improvements,
		Formula:         item.Formula,
		PostTemplate:    item.PostTemplate,
		HookPattern:     item.HookPattern,
		Structure:       item.Structure,
		ReplicationTips: item.ReplicationTips,
		Avoid:           item.Avoid,
		Tags:            item.Tags,
		CreateAt:        item.CreateAt,
		UpdateAt:        item.UpdateAt,
	}
}

func toSourceMetrics(data *types.ContentFormulaSourceMetricsData) *cfentity.SourceMetrics {
	if data == nil {
		return nil
	}
	return &cfentity.SourceMetrics{
		LikeCount:   data.LikeCount,
		ReplyCount:  data.ReplyCount,
		Views:       data.Views,
		RepostCount: data.RepostCount,
		QuoteCount:  data.QuoteCount,
		Shares:      data.Shares,
	}
}
