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

package member

import (
	"context"

	placementusecase "haixun-backend/internal/model/placement/usecase"
	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"

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

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

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

func (l *UpdateMemberPlacementSettingsLogic) UpdateMemberPlacementSettings(req *types.UpdateMemberPlacementSettingsReq) (resp *types.MemberPlacementSettingsData, err error) {
	tenantID, uid, err := actorFrom(l.ctx)
	if err != nil {
		return nil, err
	}
	settings, err := l.svcCtx.Placement.Update(l.ctx, tenantID, uid, placementusecase.SettingsPatch{
		WebSearchProvider: req.WebSearchProvider,
		BraveAPIKey:       req.BraveAPIKey,
		ExaAPIKey:         req.ExaAPIKey,
		BraveCountry:      req.BraveCountry,
		BraveSearchLang:   req.BraveSearchLang,
		ExaUserLocation:   req.ExaUserLocation,
		ExpandStrategy:    req.ExpandStrategy,
	})
	if err != nil {
		return nil, err
	}
	data := toPlacementSettingsData(settings)
	return &data, nil
}
