package TwiApi

import (
	"net/http"
	"strconv"

	"github.com/dghubble/oauth1"
	"go.uber.org/zap"
	"courseSign/server/global"
	"courseSign/server/utils"
)

func GetOauthConfig(consumerKey,consumerSecret string) *oauth1.Config {
	config := oauth1.NewConfig(consumerKey, consumerSecret)
	config.Endpoint = oauth1.Endpoint{
		RequestTokenURL: "https://api.twitter.com/oauth/request_token",
		AccessTokenURL:    "https://api.twitter.com/oauth/access_token",
		AuthorizeURL:  "https://api.twitter.com/oauth/authorize",
	}
	return config
}

func GetLimitRate(header http.Header,url string) error {
	xrll := header.Get("x-rate-limit-limit")
	xrlr := header.Get("x-rate-limit-reset")
	xrlre := header.Get("x-rate-limit-remaining")
	reset ,_ := strconv.Atoi(xrlr)
	resetDate := utils.GetDate(int64(reset))
	global.GVA_LOG.Info("API LIMIT",zap.String("url",url),zap.String("接口上限",xrll),zap.Any("接口重置时间",resetDate),zap.String("剩余次数",xrlre))
	return nil
}

const (
	TWI_USERS_ME = ""
)