//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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.

//
// This source code is part of the near-RT RIC (RAN Intelligent Controller)
// platform project (RICP).

// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// 	protoc-gen-go v1.26.0
// 	protoc        v3.15.8
// source: cell.proto

package entities

import (
	protoreflect "google.golang.org/protobuf/reflect/protoreflect"
	protoimpl "google.golang.org/protobuf/runtime/protoimpl"
	reflect "reflect"
	sync "sync"
)

const (
	// Verify that this generated code is sufficiently up-to-date.
	_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
	// Verify that runtime/protoimpl is sufficiently up-to-date.
	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)

type Cell_Type int32

const (
	Cell_UNKNOWN_CELL Cell_Type = 0
	Cell_LTE_CELL     Cell_Type = 1
	Cell_NR_CELL      Cell_Type = 2
)

// Enum value maps for Cell_Type.
var (
	Cell_Type_name = map[int32]string{
		0: "UNKNOWN_CELL",
		1: "LTE_CELL",
		2: "NR_CELL",
	}
	Cell_Type_value = map[string]int32{
		"UNKNOWN_CELL": 0,
		"LTE_CELL":     1,
		"NR_CELL":      2,
	}
)

func (x Cell_Type) Enum() *Cell_Type {
	p := new(Cell_Type)
	*p = x
	return p
}

func (x Cell_Type) String() string {
	return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}

func (Cell_Type) Descriptor() protoreflect.EnumDescriptor {
	return file_cell_proto_enumTypes[0].Descriptor()
}

func (Cell_Type) Type() protoreflect.EnumType {
	return &file_cell_proto_enumTypes[0]
}

func (x Cell_Type) Number() protoreflect.EnumNumber {
	return protoreflect.EnumNumber(x)
}

// Deprecated: Use Cell_Type.Descriptor instead.
func (Cell_Type) EnumDescriptor() ([]byte, []int) {
	return file_cell_proto_rawDescGZIP(), []int{0, 0}
}

type Cell struct {
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

	Type Cell_Type `protobuf:"varint,1,opt,name=type,proto3,enum=entities.Cell_Type" json:"type,omitempty"`
	// Types that are assignable to Cell:
	//	*Cell_ServedCellInfo
	//	*Cell_ServedNrCell
	Cell isCell_Cell `protobuf_oneof:"cell"`
}

func (x *Cell) Reset() {
	*x = Cell{}
	if protoimpl.UnsafeEnabled {
		mi := &file_cell_proto_msgTypes[0]
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		ms.StoreMessageInfo(mi)
	}
}

func (x *Cell) String() string {
	return protoimpl.X.MessageStringOf(x)
}

func (*Cell) ProtoMessage() {}

func (x *Cell) ProtoReflect() protoreflect.Message {
	mi := &file_cell_proto_msgTypes[0]
	if protoimpl.UnsafeEnabled && x != nil {
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		if ms.LoadMessageInfo() == nil {
			ms.StoreMessageInfo(mi)
		}
		return ms
	}
	return mi.MessageOf(x)
}

// Deprecated: Use Cell.ProtoReflect.Descriptor instead.
func (*Cell) Descriptor() ([]byte, []int) {
	return file_cell_proto_rawDescGZIP(), []int{0}
}

func (x *Cell) GetType() Cell_Type {
	if x != nil {
		return x.Type
	}
	return Cell_UNKNOWN_CELL
}

func (m *Cell) GetCell() isCell_Cell {
	if m != nil {
		return m.Cell
	}
	return nil
}

func (x *Cell) GetServedCellInfo() *ServedCellInfo {
	if x, ok := x.GetCell().(*Cell_ServedCellInfo); ok {
		return x.ServedCellInfo
	}
	return nil
}

func (x *Cell) GetServedNrCell() *ServedNRCell {
	if x, ok := x.GetCell().(*Cell_ServedNrCell); ok {
		return x.ServedNrCell
	}
	return nil
}

type isCell_Cell interface {
	isCell_Cell()
}

type Cell_ServedCellInfo struct {
	ServedCellInfo *ServedCellInfo `protobuf:"bytes,2,opt,name=served_cell_info,json=servedCellInfo,proto3,oneof"`
}

type Cell_ServedNrCell struct {
	ServedNrCell *ServedNRCell `protobuf:"bytes,3,opt,name=served_nr_cell,json=servedNrCell,proto3,oneof"`
}

func (*Cell_ServedCellInfo) isCell_Cell() {}

func (*Cell_ServedNrCell) isCell_Cell() {}

var File_cell_proto protoreflect.FileDescriptor

var file_cell_proto_rawDesc = []byte{
	0x0a, 0x0a, 0x63, 0x65, 0x6c, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x08, 0x65, 0x6e,
	0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x1a, 0x09, 0x67, 0x6e, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74,
	0x6f, 0x1a, 0x09, 0x65, 0x6e, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xf2, 0x01, 0x0a,
	0x04, 0x43, 0x65, 0x6c, 0x6c, 0x12, 0x27, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20,
	0x01, 0x28, 0x0e, 0x32, 0x13, 0x2e, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x2e, 0x43,
	0x65, 0x6c, 0x6c, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x44,
	0x0a, 0x10, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x5f, 0x63, 0x65, 0x6c, 0x6c, 0x5f, 0x69, 0x6e,
	0x66, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x65, 0x6e, 0x74, 0x69, 0x74,
	0x69, 0x65, 0x73, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x64, 0x43, 0x65, 0x6c, 0x6c, 0x49, 0x6e,
	0x66, 0x6f, 0x48, 0x00, 0x52, 0x0e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x43, 0x65, 0x6c, 0x6c,
	0x49, 0x6e, 0x66, 0x6f, 0x12, 0x3e, 0x0a, 0x0e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x5f, 0x6e,
	0x72, 0x5f, 0x63, 0x65, 0x6c, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x65,
	0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x64, 0x4e, 0x52,
	0x43, 0x65, 0x6c, 0x6c, 0x48, 0x00, 0x52, 0x0c, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x4e, 0x72,
	0x43, 0x65, 0x6c, 0x6c, 0x22, 0x33, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x10, 0x0a, 0x0c,
	0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x5f, 0x43, 0x45, 0x4c, 0x4c, 0x10, 0x00, 0x12, 0x0c,
	0x0a, 0x08, 0x4c, 0x54, 0x45, 0x5f, 0x43, 0x45, 0x4c, 0x4c, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07,
	0x4e, 0x52, 0x5f, 0x43, 0x45, 0x4c, 0x4c, 0x10, 0x02, 0x42, 0x06, 0x0a, 0x04, 0x63, 0x65, 0x6c,
	0x6c, 0x42, 0x33, 0x5a, 0x31, 0x67, 0x65, 0x72, 0x72, 0x69, 0x74, 0x2e, 0x6f, 0x2d, 0x72, 0x61,
	0x6e, 0x2d, 0x73, 0x63, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x72, 0x2f, 0x72, 0x69, 0x63, 0x2d, 0x70,
	0x6c, 0x74, 0x2f, 0x6e, 0x6f, 0x64, 0x65, 0x62, 0x2d, 0x72, 0x6e, 0x69, 0x62, 0x2f, 0x65, 0x6e,
	0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}

var (
	file_cell_proto_rawDescOnce sync.Once
	file_cell_proto_rawDescData = file_cell_proto_rawDesc
)

func file_cell_proto_rawDescGZIP() []byte {
	file_cell_proto_rawDescOnce.Do(func() {
		file_cell_proto_rawDescData = protoimpl.X.CompressGZIP(file_cell_proto_rawDescData)
	})
	return file_cell_proto_rawDescData
}

var file_cell_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_cell_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_cell_proto_goTypes = []interface{}{
	(Cell_Type)(0),         // 0: entities.Cell.Type
	(*Cell)(nil),           // 1: entities.Cell
	(*ServedCellInfo)(nil), // 2: entities.ServedCellInfo
	(*ServedNRCell)(nil),   // 3: entities.ServedNRCell
}
var file_cell_proto_depIdxs = []int32{
	0, // 0: entities.Cell.type:type_name -> entities.Cell.Type
	2, // 1: entities.Cell.served_cell_info:type_name -> entities.ServedCellInfo
	3, // 2: entities.Cell.served_nr_cell:type_name -> entities.ServedNRCell
	3, // [3:3] is the sub-list for method output_type
	3, // [3:3] is the sub-list for method input_type
	3, // [3:3] is the sub-list for extension type_name
	3, // [3:3] is the sub-list for extension extendee
	0, // [0:3] is the sub-list for field type_name
}

func init() { file_cell_proto_init() }
func file_cell_proto_init() {
	if File_cell_proto != nil {
		return
	}
	file_gnb_proto_init()
	file_enb_proto_init()
	if !protoimpl.UnsafeEnabled {
		file_cell_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
			switch v := v.(*Cell); i {
			case 0:
				return &v.state
			case 1:
				return &v.sizeCache
			case 2:
				return &v.unknownFields
			default:
				return nil
			}
		}
	}
	file_cell_proto_msgTypes[0].OneofWrappers = []interface{}{
		(*Cell_ServedCellInfo)(nil),
		(*Cell_ServedNrCell)(nil),
	}
	type x struct{}
	out := protoimpl.TypeBuilder{
		File: protoimpl.DescBuilder{
			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
			RawDescriptor: file_cell_proto_rawDesc,
			NumEnums:      1,
			NumMessages:   1,
			NumExtensions: 0,
			NumServices:   0,
		},
		GoTypes:           file_cell_proto_goTypes,
		DependencyIndexes: file_cell_proto_depIdxs,
		EnumInfos:         file_cell_proto_enumTypes,
		MessageInfos:      file_cell_proto_msgTypes,
	}.Build()
	File_cell_proto = out.File
	file_cell_proto_rawDesc = nil
	file_cell_proto_goTypes = nil
	file_cell_proto_depIdxs = nil
}
