/*
 * Copyright 2021 CloudWeGo Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package rpcinfo_test

import (
	"context"
	"time"

	"github.com/cloudwego/kitex/pkg/rpcinfo"
	"github.com/cloudwego/kitex/pkg/serviceinfo"
	"github.com/cloudwego/kitex/pkg/stats"
	"github.com/cloudwego/kitex/transport"
)

var _ rpcinfo.RPCConfig = &MockRPCConfig{}

// MockRPCConfig implements the rpcinfo.RPCConfig interface.
type MockRPCConfig struct {
	RPCTimeoutFunc        func() (r time.Duration)
	ConnectTimeoutFunc    func() (r time.Duration)
	ReadWriteTimeoutFunc  func() (r time.Duration)
	IOBufferSizeFunc      func() (r int)
	TransportProtocolFunc func() transport.Protocol
	InteractionModeFunc   func() (r rpcinfo.InteractionMode)
}

func (m *MockRPCConfig) PayloadCodec() serviceinfo.PayloadCodec {
	// TODO implement me
	panic("implement me")
}

func (m *MockRPCConfig) InteractionMode() (r rpcinfo.InteractionMode) {
	if m.InteractionModeFunc != nil {
		return m.InteractionModeFunc()
	}
	return
}

// RPCTimeout implements the rpcinfo.RPCConfig interface.
func (m *MockRPCConfig) RPCTimeout() (r time.Duration) {
	if m.RPCTimeoutFunc != nil {
		return m.RPCTimeoutFunc()
	}
	return
}

// ConnectTimeout implements the rpcinfo.RPCConfig interface.
func (m *MockRPCConfig) ConnectTimeout() (r time.Duration) {
	if m.ConnectTimeoutFunc != nil {
		return m.ConnectTimeoutFunc()
	}
	return
}

// ReadWriteTimeout implements the rpcinfo.RPCConfig interface.
func (m *MockRPCConfig) ReadWriteTimeout() (r time.Duration) {
	if m.ReadWriteTimeoutFunc != nil {
		return m.ReadWriteTimeoutFunc()
	}
	return
}

// IOBufferSize implements the rpcinfo.RPCConfig interface.
func (m *MockRPCConfig) IOBufferSize() (r int) {
	if m.IOBufferSizeFunc != nil {
		return m.IOBufferSizeFunc()
	}
	return
}

// TransportProtocol implements the rpcinfo.RPCConfig interface.
func (m *MockRPCConfig) TransportProtocol() (r transport.Protocol) {
	if m.TransportProtocolFunc != nil {
		return m.TransportProtocolFunc()
	}
	return
}

func (m *MockRPCConfig) StreamRecvTimeout() time.Duration {
	return time.Duration(0)
}

type MockRPCStats struct{}

func (m *MockRPCStats) Record(context.Context, stats.Event, stats.Status, string) {}
func (m *MockRPCStats) SendSize() uint64                                          { return 0 }
func (m *MockRPCStats) RecvSize() uint64                                          { return 0 }
func (m *MockRPCStats) Error() error                                              { return nil }
func (m *MockRPCStats) Panicked() (yes bool, val interface{})                     { return }
func (m *MockRPCStats) GetEvent(event stats.Event) (e rpcinfo.Event)              { return }
func (m *MockRPCStats) Level() (lv stats.Level)                                   { return }
func (m *MockRPCStats) CopyForRetry() rpcinfo.RPCStats                            { return nil }
func (m *MockRPCStats) LastSendSize() uint64                                      { return 0 }
func (m *MockRPCStats) LastRecvSize() uint64                                      { return 0 }
