package radar

import (
	"context"

	"apps/backend/internal/logic/radarmap"
	"apps/backend/internal/svc"
	"apps/backend/internal/types"

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

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

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

func (l *UpsertServiceProfileLogic) UpsertServiceProfile(req *types.UpsertServiceProfileReq) (resp *types.ServiceProfilePublic, err error) {
	uid, err := ownerUID(l.ctx)
	if err != nil {
		return nil, err
	}
	p, err := l.svcCtx.Radar.UpsertServiceProfile(l.ctx, uid, radarmap.ServiceProfileInput(req))
	if err != nil {
		return nil, err
	}
	return radarmap.ServiceProfile(p), nil
}
