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

package persona

import (
	"context"

	stylepresetdomain "haixun-backend/internal/model/style_preset/domain/usecase"
	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"

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

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

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

func (l *UpsertStylePresetLogic) UpsertStylePreset(req *types.UpsertStylePresetHandlerReq) (resp *types.StylePresetData, err error) {
	tenantID, uid, err := actorFrom(l.ctx)
	if err != nil {
		return nil, err
	}
	item, err := l.svcCtx.StylePreset.Upsert(l.ctx, stylepresetdomain.UpsertRequest{
		TenantID: tenantID, OwnerUID: uid, PersonaID: req.ID, PresetID: req.PresetID,
		Name: req.Name, Tone: req.Tone, CTA: req.CTA, BannedWords: req.BannedWords, Notes: req.Notes, Apply: req.Apply,
	})
	if err != nil {
		return nil, err
	}
	data := toStylePresetData(*item)
	return &data, nil
}
