package mysql

import (
	"math"
	"testing"
)

// TestParseVipDailyCoinRebateAmount 只接受 JSON 正 int64；不允许字符串、浮点数、零、负数或溢出值。
func TestParseVipDailyCoinRebateAmount(t *testing.T) {
	testCases := []struct {
		name    string
		payload string
		want    int64
		valid   bool
	}{
		{name: "positive", payload: `{"coin_amount":123}`, want: 123, valid: true},
		{name: "max int64", payload: `{"coin_amount":9223372036854775807}`, want: math.MaxInt64, valid: true},
		{name: "missing", payload: `{}`, valid: false},
		{name: "string", payload: `{"coin_amount":"123"}`, valid: false},
		{name: "float", payload: `{"coin_amount":1.5}`, valid: false},
		{name: "zero", payload: `{"coin_amount":0}`, valid: false},
		{name: "negative", payload: `{"coin_amount":-1}`, valid: false},
		{name: "overflow", payload: `{"coin_amount":9223372036854775808}`, valid: false},
		{name: "array", payload: `[]`, valid: false},
	}
	for _, testCase := range testCases {
		t.Run(testCase.name, func(t *testing.T) {
			amount, err := parseVipDailyCoinRebateAmount(testCase.payload)
			if testCase.valid {
				if err != nil || amount != testCase.want {
					t.Fatalf("parse positive int64 mismatch: amount=%d err=%v", amount, err)
				}
				return
			}
			if err == nil {
				t.Fatalf("invalid payload unexpectedly parsed as %d", amount)
			}
		})
	}
}
