// 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 CreatePersonaLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

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

func (l *CreatePersonaLogic) CreatePersona(req *types.CreatePersonaReq) (resp *types.PersonaData, err error) {
	tenantID, uid, err := actorFrom(l.ctx)
	if err != nil {
		return nil, err
	}
	displayName := ""
	if req != nil {
		displayName = req.DisplayName
	}
	item, err := l.svcCtx.Persona.Create(l.ctx, domusecase.CreateRequest{
		TenantID:    tenantID,
		OwnerUID:    uid,
		DisplayName: displayName,
	})
	if err != nil {
		return nil, err
	}
	out := toPersonaData(*item)
	return &out, nil
}
