package threads_account

import (
	"context"
	"fmt"

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

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

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

func (l *DeleteContentFormulaLogic) DeleteContentFormula(req *types.GetContentFormulaHandlerReq) (*types.DeleteContentFormulaData, error) {
	tenantID, uid, err := actorFrom(l.ctx)
	if err != nil {
		return nil, err
	}
	if err := l.svcCtx.ContentFormula.Delete(l.ctx, tenantID, uid, req.ID, req.FormulaID); err != nil {
		return nil, err
	}
	return &types.DeleteContentFormulaData{
		FormulaID: req.FormulaID,
		Message:   fmt.Sprintf("已刪除公式 %s", req.FormulaID),
	}, nil
}
