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

package persona

import (
	"context"

	domusecase "haixun-backend/internal/model/persona/domain/usecase"
	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"

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

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

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

func (l *UpdatePersonaLogic) UpdatePersona(req *types.UpdatePersonaHandlerReq) (resp *types.PersonaData, err error) {
	tenantID, uid, err := actorFrom(l.ctx)
	if err != nil {
		return nil, err
	}
	item, err := l.svcCtx.Persona.Update(l.ctx, domusecase.UpdateRequest{
		TenantID:  tenantID,
		OwnerUID:  uid,
		PersonaID: req.ID,
		Patch:     toPersonaPatch(&req.UpdatePersonaReq),
	})
	if err != nil {
		return nil, err
	}
	out := toPersonaData(*item)
	return &out, nil
}
