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

package job

import (
	"context"
	"strings"

	app "haixun-backend/internal/library/errors"
	"haixun-backend/internal/library/errors/code"
	personausecase "haixun-backend/internal/model/persona/domain/usecase"
	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"

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

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

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

func (l *StorePersonaStyleProfileFromWorkerLogic) StorePersonaStyleProfileFromWorker(req *types.StorePersonaStyleProfileReq) (resp *types.StorePersonaStyleProfileData, err error) {
	if strings.TrimSpace(req.StyleProfile) == "" {
		return nil, app.For(code.Persona).InputMissingRequired("style_profile is required")
	}
	profile := strings.TrimSpace(req.StyleProfile)
	benchmark := strings.TrimPrefix(strings.TrimSpace(req.StyleBenchmark), "@")
	item, err := l.svcCtx.Persona.Update(l.ctx, personausecase.UpdateRequest{
		TenantID:  req.TenantID,
		OwnerUID:  req.OwnerUID,
		PersonaID: req.ID,
		Patch: personausecase.PersonaPatch{
			StyleProfile:   &profile,
			StyleBenchmark: &benchmark,
		},
	})
	if err != nil {
		return nil, err
	}
	return &types.StorePersonaStyleProfileData{ID: item.ID, UpdateAt: item.UpdateAt}, nil
}
