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

package threads_account

import (
	"context"

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

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

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

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

func (l *UpdateThreadsAccountConnectionLogic) UpdateThreadsAccountConnection(req *types.UpdateThreadsAccountConnectionHandlerReq) (resp *types.ThreadsAccountConnectionData, err error) {
	tenantID, uid, err := actorFrom(l.ctx)
	if err != nil {
		return nil, err
	}
	data, err := l.svcCtx.ThreadsAccount.UpdateConnection(l.ctx, domusecase.UpdateConnectionRequest{
		TenantID:  tenantID,
		OwnerUID:  uid,
		AccountID: req.ID,
		Prefs:     toConnectionPatch(&req.UpdateThreadsAccountConnectionReq),
	})
	if err != nil {
		return nil, err
	}
	return toConnectionData(data), nil
}
