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

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

func (l *UpdateThreadsAccountAiSettingsLogic) UpdateThreadsAccountAiSettings(req *types.UpdateThreadsAccountAiSettingsHandlerReq) (resp *types.ThreadsAccountAiSettingsData, err error) {
	tenantID, uid, err := actorFrom(l.ctx)
	if err != nil {
		return nil, err
	}
	data, err := l.svcCtx.ThreadsAccount.UpdateAiSettings(l.ctx, tenantID, uid, req.ID, toAiSettingsPatch(&req.UpdateThreadsAccountAiSettingsReq))
	if err != nil {
		return nil, err
	}
	return toAiSettingsData(data), nil
}

func toAiSettingsPatch(req *types.UpdateThreadsAccountAiSettingsReq) domusecase.AiSettingsPatch {
	if req == nil {
		return domusecase.AiSettingsPatch{}
	}
	return domusecase.AiSettingsPatch{
		Provider:         req.Provider,
		Model:            req.Model,
		ResearchProvider: req.ResearchProvider,
		ResearchModel:    req.ResearchModel,
		ApiKeys:          req.ApiKeys,
	}
}
