package threads_account

import (
	"context"

	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"
)

type GetContentFormulaLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetContentFormulaLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetContentFormulaLogic {
	return &GetContentFormulaLogic{ctx: ctx, svcCtx: svcCtx}
}

func (l *GetContentFormulaLogic) GetContentFormula(req *types.GetContentFormulaHandlerReq) (*types.ContentFormulaData, error) {
	tenantID, uid, err := actorFrom(l.ctx)
	if err != nil {
		return nil, err
	}
	item, err := l.svcCtx.ContentFormula.Get(l.ctx, tenantID, uid, req.ID, req.FormulaID)
	if err != nil {
		return nil, err
	}
	data := toContentFormulaData(*item)
	return &data, nil
}
