package threads_account

import (
	"strings"

	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"
)

type GetThreadsOAuthConfigLogic struct {
	svcCtx *svc.ServiceContext
}

func NewGetThreadsOAuthConfigLogic(svcCtx *svc.ServiceContext) *GetThreadsOAuthConfigLogic {
	return &GetThreadsOAuthConfigLogic{svcCtx: svcCtx}
}

func (l *GetThreadsOAuthConfigLogic) GetThreadsOAuthConfig() *types.ThreadsOAuthConfigData {
	cfg := l.svcCtx.Config.ThreadsOAuth
	redirect := strings.TrimSpace(cfg.RedirectURI)
	return &types.ThreadsOAuthConfigData{
		RedirectURI:     redirect,
		SuccessRedirect: strings.TrimSpace(cfg.SuccessRedirect),
		Enabled:         strings.TrimSpace(cfg.AppID) != "" && strings.TrimSpace(cfg.AppSecret) != "" && redirect != "",
		RequiresHTTPS:   !strings.HasPrefix(strings.ToLower(redirect), "https://"),
	}
}
