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

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

func (l *ImportThreadsAccountSessionLogic) ImportThreadsAccountSession(req *types.ImportThreadsAccountSessionHandlerReq) (resp *types.ImportThreadsAccountSessionData, err error) {
	tenantID, uid, err := actorFrom(l.ctx)
	if err != nil {
		return nil, err
	}
	result, err := l.svcCtx.ThreadsAccount.ImportBrowserSession(l.ctx, domusecase.ImportBrowserSessionRequest{
		TenantID:     tenantID,
		OwnerUID:     uid,
		AccountID:    req.ID,
		StorageState: req.StorageState,
	})
	if err != nil {
		return nil, err
	}
	return &types.ImportThreadsAccountSessionData{
		Success:   true,
		Valid:     result.Valid,
		Synced:    result.Synced,
		AccountID: result.AccountID,
		Username:  result.Username,
		Message:   result.Message,
		UpdateAt:  result.UpdateAt,
	}, nil
}
