// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1

package persona

import (
	"context"

	contentops "haixun-backend/internal/model/content_ops/domain/usecase"
	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateFormulaPoolLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateFormulaPoolLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateFormulaPoolLogic {
	return &CreateFormulaPoolLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateFormulaPoolLogic) CreateFormulaPool(req *types.CreateFormulaPoolHandlerReq) (resp *types.FormulaPoolData, err error) {
	tenantID, uid, err := actorFrom(l.ctx)
	if err != nil {
		return nil, err
	}
	item, err := l.svcCtx.ContentOps.CreateFormulaPool(l.ctx, contentops.FormulaPoolInput{TenantID: tenantID, OwnerUID: uid, PersonaID: req.ID, Type: req.Type, Name: req.Name, Pattern: req.Pattern, UseCases: req.UseCases, Avoid: req.Avoid, Weight: req.Weight})
	if err != nil {
		return nil, err
	}
	data := toFormulaPoolData(*item)
	return &data, nil
}
