package mtwmapi

import (
	"fmt"
	"git.rosy.net.cn/baseapi"
	"git.rosy.net.cn/baseapi/utils"
	"go.uber.org/zap"
	"testing"
)

var (
	api         *API
	sugarLogger *zap.SugaredLogger
)

func init() {
	logger, _ := zap.NewDevelopment()
	sugarLogger = logger.Sugar()
	baseapi.Init(sugarLogger)

	// 菜市
	api = New("589", "a81eb3df418d83d6a1a4b7c572156d2f", "", "")

	// 果园
	//api = New("4123", "df2c88338b85f830cebce2a9eab56628", "", "")

	//商超
	//api = New("5873", "41c479790a76f86326f89e8048964739", "", "token_oFtkFnZqmR7QtKUeqIpJ8Q")
	//cookieStr := `
	//	acctId=57396785; token=0bWbK5VbK50E2BmIhIH2zHB-am_y7mB37yXHm6RLZWx4*; wmPoiId=-1;
	//`
	//api.SetCookieWithStr(cookieStr)
	api.SetCookieWithStr(`__jdu=16496474755891719920568; unpl=JF8EALNnNSttDU0HBElWE0BAQ1oHWw4KGEcLOmRRUVhQHlUBHlIeEBF7XlVdXhRKEh9vZxRUWFNIVQ4YBysSEXteU11bD00VB2xXVgQFDQ8WUUtBSUt-SF1UXVsJSxMHbG4GZG1bS2QFGjIbFRVDWlFYWA5PEwpnZwNUVVBIVQEcCysiF3ttZFpaCUMTC19mNVVtGh8IDRwGGhMQBl1TW1UPThEGaWMBXVVYTVQNEwEaFhdCbVVuXg; areaId=22; ipLoc-djd=22-1930-0-0; PCSYCityID=CN_510000_510100_0; __jdv=122270672|baidu|-|organic|notset|1649658041982; pinId=0P4L2K_8z11ZUOOc8Pyh4w; pin=jxc4liulei; unick=jxc4liulei; _tp=SNh2AuY0LCWg91owlmuS1Q%3D%3D; _pst=jxc4liulei; ceshi3.com=000; _vender_=TNK3O6PALVQGG3P24NJQFXSBHYQNFQDBDAAAFNJIJAECQG2WSQGU5RJ6KSCMVVQQRHQZD6AECSQT3YKKYMRQJDFZHEEPXXHCR3STQEL55G2S4OB7Q6QUPCVBRUAZKDRVRF2MP5BK57JOU57NKALCQQWNR5XRJWJ4AGVNOAVSZUQ4QLRQZLY62QPOMBQHAQAGNLFRNQDWAO2N2HSD33FC2BJBV3S3QAJEAEJCDK4QQCZD6R72KBKNNWCITHQ32SVZKLN526Z2KM5T3DCVCND4YAK4AZMYIVI7ULYSDQD34K63YVC2TN5AJHZFWVYZEQGPZ65I6MTWTEDVOTLQ5D2AY2PBT4JHYXKEV6DFST3FWH5NOTDOJY3IASEKA7SG6LJSRN63HAW554GZVREIKMQHQAC5IVI445ONJ6GMFECU4SNRFRAYRKKYNISVYBKRTNHJCGFX2442SELHC4MUUVLVNBKEDYTDRCC4ZMMDMWSG75UUSWWXISJA; wlfstk_smdl=91h55jyt5sfm1901tdbgehyi67o5iaor; language=zh_CN; TrackID=1oqBrsNfaNsPFZVtK-124Hk1wwpg113ZwmS2Cajw8VwRsb0RCE3ph1kEhr7BLLOhyaQ196cgJsdscvrvGuBRoZm_dfJ1RuXfLocegNnMjRM8; thor=01BA10CC3862D8315A8F658F7DD2838C910211F45B05336172446EFDFC25E684EB4B9A81E2F1012525DBB65E171F7F5049FBFB076DA4FAC0AE7898C136389DC95DE18C259981364B775EAB7385F4CFFB2BEA505D94D2C1B8D5899C421825A32F0E60967FBF20170B0F1F31A27F795E2C40F4F9A141DD7260894C5EA879FE0810E99DDEFFC34ED45459429571A06DB76E; b-sec=3XU3DWGGC3WZSRRUDORQHBODFJXKGJRSNQI4WVMLXDV5NBOUPIJGYAR6Q5ZBP3KGR7GY3A37P62ZS; __jda=191429163.16496474755891719920568.1649647476.1649658035.1649658042.4; __jdc=191429163; 3AB9D23F7A4B3C9B=CKENC5MAUU744ZQDKVRY2L7UIJ23PJRDYJ6HF3ZMQHC5FFD46FMUQXRINFCOC4SKHL5MU3PPNPP4C4AX5ZYBXJ7LZ4; _base_=YKH2KDFHMOZBLCUV7NSRBWQUJPBI7JIMU5R3EFJ5UDHJ5LCU7R2NILKK5UJ6GLA2RGYT464UKXAI5KK7PNC5B5UHJ2HVQ4ENFP57OC2XJVD24IJG4VRA63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Q5FHPNMZOCRLURVOQKFM7B2D4BBXHS2QRSAAEO6RPWOL62CWNGPOHMGMAGVAJ77C4IC2ET3NVN6PBVCLI56OPZPR7RNFOAEYFZTP2BSCS5ZMNTWN4HIOX5NUKDT5EUE5QQ722X2U2H7DKPHIF7OHQ6IR4HMB5NA7ACWBHEXOENOEOZZIHVQJO7KJEXLBYIYCIDSN4MFK5XWTHEBPJHFWGJBRDK2VBA6IMVCSGASA4TPDBKXN5UZZAL2JZNRSJTR363NRPUBYOPSTMWNXIMF4UYZPUUZPLTJX56EXDHFSRQF3F4FZXK47M3A33GZHU6UCVEAOAOFE3CAHDO4DMIK7334CESHKG3LT2KSPPDT3GXU5UUQOJGGQTYURJRST3PF7U6LS5URX2WPD7XV3OBKJQ2C3NFHU35TKJPWKEJUIFFUHXPJBS6AEJ7JV4RL5QDPT7ZGGIHSED3ZCDW563MYWFUFFCNMWQEZXMPDHUOHRDBNSOWPCAI4ZR4B4NENJLWZUO3XKK4L3AUAJKICWYY6MNDA`)

}

func TestAccessAPI(t *testing.T) {
	result, err := api.AccessAPI("poi/getids", true, nil)
	if err != nil {
		t.Fatal(err)
	}
	t.Log(utils.Format4Output(result, false))
}

func TestGetOAuthCode(t *testing.T) {
	result, err := api.GetOAuthCode("9472886")
	if err != nil {
		t.Fatal(err)
	}
	fmt.Println(utils.Format4Output(result, false))
	t.Log(utils.Format4Output(result, false))
}

func TestPreparationMealComplete(t *testing.T) {
	api.PreparationMealComplete(3901564910320888932)
}

func TestGetAccessToken(t *testing.T) {
	result, err := api.GetAccessToken("code_ra0oUBjsRwRf0f5m0wJB9g")
	if err != nil {
		t.Fatal(err)
	}
	fmt.Println(utils.Format4Output(result, false))
	t.Log(utils.Format4Output(result, false))
}

func TestGetAccessToken2(t *testing.T) {
	result, err := api.GetAccessToken2("18048546") //refresh_token_pLG7Jw7g9mu7oOzNSuJIUg
	if err != nil {
		t.Fatal(err)
	}
	fmt.Println(utils.Format4Output(result.AccessToken, false))
	t.Log(utils.Format4Output(result, false))
}

func TestRefreshAccessToken(t *testing.T) {
	result, err := api.RefreshAccessToken("refresh_token_jajfdTMzYvB28v-3q4RFgQ") //token_qbAyE3ajWYT8ecwoI-FMjw
	if err != nil {
		t.Fatal(err)
	}
	fmt.Println(utils.Format4Output(result, false))
	t.Log(utils.Format4Output(result, false))
}
