/*
 * Copyright 2025 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 message

import (
	"github.com/cloudwego/kitex/pkg/remote"
	"github.com/cloudwego/kitex/pkg/rpcinfo"
)

var _ remote.Message = &MockMessage{}

type MockMessage struct {
	RPCInfoFunc         func() rpcinfo.RPCInfo
	DataFunc            func() interface{}
	NewDataFunc         func(method string) (ok bool)
	MessageTypeFunc     func() remote.MessageType
	SetMessageTypeFunc  func(remote.MessageType)
	RPCRoleFunc         func() remote.RPCRole
	PayloadLenFunc      func() int
	SetPayloadLenFunc   func(size int)
	TransInfoFunc       func() remote.TransInfo
	TagsFunc            func() map[string]interface{}
	PayloadCodecFunc    func() remote.PayloadCodec
	SetPayloadCodecFunc func(pc remote.PayloadCodec)
	RecycleFunc         func()
}

func (m *MockMessage) RPCInfo() rpcinfo.RPCInfo {
	if m.RPCInfoFunc != nil {
		return m.RPCInfoFunc()
	}
	return nil
}

func (m *MockMessage) Data() interface{} {
	if m.DataFunc != nil {
		return m.DataFunc()
	}
	return nil
}

func (m *MockMessage) NewData(method string) (ok bool) {
	if m.NewDataFunc != nil {
		return m.NewDataFunc(method)
	}
	return false
}

func (m *MockMessage) MessageType() (mt remote.MessageType) {
	if m.MessageTypeFunc != nil {
		return m.MessageTypeFunc()
	}
	return
}

func (m *MockMessage) SetMessageType(mt remote.MessageType) {
	if m.SetMessageTypeFunc != nil {
		m.SetMessageTypeFunc(mt)
	}
}

func (m *MockMessage) RPCRole() (r remote.RPCRole) {
	if m.RPCRoleFunc != nil {
		return m.RPCRoleFunc()
	}
	return
}

func (m *MockMessage) PayloadLen() int {
	if m.PayloadLenFunc != nil {
		return m.PayloadLenFunc()
	}
	return 0
}

func (m *MockMessage) SetPayloadLen(size int) {
	if m.SetPayloadLenFunc != nil {
		m.SetPayloadLenFunc(size)
	}
}

func (m *MockMessage) TransInfo() remote.TransInfo {
	if m.TransInfoFunc != nil {
		return m.TransInfoFunc()
	}
	return nil
}

func (m *MockMessage) Tags() map[string]interface{} {
	if m.TagsFunc != nil {
		return m.TagsFunc()
	}
	return nil
}

func (m *MockMessage) PayloadCodec() remote.PayloadCodec {
	if m.PayloadCodecFunc != nil {
		return m.PayloadCodecFunc()
	}
	return nil
}

func (m *MockMessage) SetPayloadCodec(pc remote.PayloadCodec) {
	if m.SetPayloadCodecFunc != nil {
		m.SetPayloadCodecFunc(pc)
	}
}

func (m *MockMessage) Recycle() {
	if m.RecycleFunc != nil {
		m.RecycleFunc()
	}
}
