package wechat

import (
	"context"
	"net/http"
)

// MockOfficialAccountService Mock 微信公众号服务（实现 OfficialAccountServiceInterface）
type MockOfficialAccountService struct {
	GetUserInfoFn         func(ctx context.Context, code string) (openID, unionID string, err error)
	GetUserInfoDetailedFn func(ctx context.Context, code string) (*UserInfo, error)
	GetUserInfoByTokenFn  func(ctx context.Context, accessToken, openID string) (*UserInfo, error)
}

// GetUserInfo Mock 实现
func (m *MockOfficialAccountService) GetUserInfo(ctx context.Context, code string) (openID, unionID string, err error) {
	if m.GetUserInfoFn != nil {
		return m.GetUserInfoFn(ctx, code)
	}
	return "", "", nil
}

// GetUserInfoDetailed Mock 实现
func (m *MockOfficialAccountService) GetUserInfoDetailed(ctx context.Context, code string) (*UserInfo, error) {
	if m.GetUserInfoDetailedFn != nil {
		return m.GetUserInfoDetailedFn(ctx, code)
	}
	return nil, nil
}

// GetUserInfoByToken Mock 实现
func (m *MockOfficialAccountService) GetUserInfoByToken(ctx context.Context, accessToken, openID string) (*UserInfo, error) {
	if m.GetUserInfoByTokenFn != nil {
		return m.GetUserInfoByTokenFn(ctx, accessToken, openID)
	}
	return nil, nil
}

// MockPaymentService Mock 微信支付服务（实现 PaymentServiceInterface）
type MockPaymentService struct {
	CreateJSAPIOrderFn    func(ctx context.Context, orderNo, description, openID string, amount int) (*JSAPIPayResult, error)
	CreateH5OrderFn       func(ctx context.Context, orderNo, description string, amount int, sceneInfo *H5SceneInfo) (*H5PayResult, error)
	QueryOrderFn          func(ctx context.Context, orderNo string) (*OrderInfo, error)
	CloseOrderFn          func(ctx context.Context, orderNo string) error
	HandlePaymentNotifyFn func(r *http.Request, callback PaymentNotifyCallback) (*http.Response, error)
}

// CreateJSAPIOrder Mock 实现
func (m *MockPaymentService) CreateJSAPIOrder(ctx context.Context, orderNo, description, openID string, amount int) (*JSAPIPayResult, error) {
	if m.CreateJSAPIOrderFn != nil {
		return m.CreateJSAPIOrderFn(ctx, orderNo, description, openID, amount)
	}
	return nil, nil
}

// CreateH5Order Mock 实现
func (m *MockPaymentService) CreateH5Order(ctx context.Context, orderNo, description string, amount int, sceneInfo *H5SceneInfo) (*H5PayResult, error) {
	if m.CreateH5OrderFn != nil {
		return m.CreateH5OrderFn(ctx, orderNo, description, amount, sceneInfo)
	}
	return nil, nil
}

// QueryOrder Mock 实现
func (m *MockPaymentService) QueryOrder(ctx context.Context, orderNo string) (*OrderInfo, error) {
	if m.QueryOrderFn != nil {
		return m.QueryOrderFn(ctx, orderNo)
	}
	return nil, nil
}

// CloseOrder Mock 实现
func (m *MockPaymentService) CloseOrder(ctx context.Context, orderNo string) error {
	if m.CloseOrderFn != nil {
		return m.CloseOrderFn(ctx, orderNo)
	}
	return nil
}

// HandlePaymentNotify Mock 实现（简化版）
func (m *MockPaymentService) HandlePaymentNotify(r *http.Request, callback PaymentNotifyCallback) (*http.Response, error) {
	if m.HandlePaymentNotifyFn != nil {
		return m.HandlePaymentNotifyFn(r, callback)
	}
	return &http.Response{StatusCode: 200}, nil
}

var (
	_ OfficialAccountServiceInterface = (*MockOfficialAccountService)(nil)
	_ PaymentServiceInterface         = (*MockPaymentService)(nil)
)
