// automatically generated by the FlatBuffers compiler, do not modify
// @generated
extern crate alloc;
extern crate flatbuffers;
use alloc::boxed::Box;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use core::mem;
use core::cmp::Ordering;
extern crate serde;
use self::serde::ser::{Serialize, Serializer, SerializeStruct};
use self::flatbuffers::{EndianScalar, Follow};
use super::*;
pub enum TestSimpleTableWithEnumOffset {}
#[derive(Copy, Clone, PartialEq)]

pub struct TestSimpleTableWithEnum<'a> {
  pub _tab: flatbuffers::Table<'a>,
}

impl<'a> flatbuffers::Follow<'a> for TestSimpleTableWithEnum<'a> {
  type Inner = TestSimpleTableWithEnum<'a>;
  #[inline]
  unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
    Self { _tab: unsafe { flatbuffers::Table::new(buf, loc) } }
  }
}

impl<'a> TestSimpleTableWithEnum<'a> {
  pub const VT_COLOR: flatbuffers::VOffsetT = 4;

  pub const fn get_fully_qualified_name() -> &'static str {
    "MyGame.Example.TestSimpleTableWithEnum"
  }

  #[inline]
  pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
    TestSimpleTableWithEnum { _tab: table }
  }
  #[allow(unused_mut)]
  pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>(
    _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>,
    args: &'args TestSimpleTableWithEnumArgs
  ) -> flatbuffers::WIPOffset<TestSimpleTableWithEnum<'bldr>> {
    let mut builder = TestSimpleTableWithEnumBuilder::new(_fbb);
    builder.add_color(args.color);
    builder.finish()
  }

  pub fn unpack(&self) -> TestSimpleTableWithEnumT {
    let color = self.color();
    TestSimpleTableWithEnumT {
      color,
    }
  }

  #[inline]
  pub fn color(&self) -> Color {
    // Safety:
    // Created from valid Table for this object
    // which contains a valid value in this slot
    unsafe { self._tab.get::<Color>(TestSimpleTableWithEnum::VT_COLOR, Some(Color::Green)).unwrap()}
  }
}

impl flatbuffers::Verifiable for TestSimpleTableWithEnum<'_> {
  #[inline]
  fn run_verifier(
    v: &mut flatbuffers::Verifier, pos: usize
  ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
    use self::flatbuffers::Verifiable;
    v.visit_table(pos)?
     .visit_field::<Color>("color", Self::VT_COLOR, false)?
     .finish();
    Ok(())
  }
}
pub struct TestSimpleTableWithEnumArgs {
    pub color: Color,
}
impl<'a> Default for TestSimpleTableWithEnumArgs {
  #[inline]
  fn default() -> Self {
    TestSimpleTableWithEnumArgs {
      color: Color::Green,
    }
  }
}

impl Serialize for TestSimpleTableWithEnum<'_> {
  fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
  where
    S: Serializer,
  {
    let mut s = serializer.serialize_struct("TestSimpleTableWithEnum", 1)?;
      s.serialize_field("color", &self.color())?;
    s.end()
  }
}

pub struct TestSimpleTableWithEnumBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> {
  fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
  start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
}
impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> TestSimpleTableWithEnumBuilder<'a, 'b, A> {
  #[inline]
  pub fn add_color(&mut self, color: Color) {
    self.fbb_.push_slot::<Color>(TestSimpleTableWithEnum::VT_COLOR, color, Color::Green);
  }
  #[inline]
  pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> TestSimpleTableWithEnumBuilder<'a, 'b, A> {
    let start = _fbb.start_table();
    TestSimpleTableWithEnumBuilder {
      fbb_: _fbb,
      start_: start,
    }
  }
  #[inline]
  pub fn finish(self) -> flatbuffers::WIPOffset<TestSimpleTableWithEnum<'a>> {
    let o = self.fbb_.end_table(self.start_);
    flatbuffers::WIPOffset::new(o.value())
  }
}

impl core::fmt::Debug for TestSimpleTableWithEnum<'_> {
  fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    let mut ds = f.debug_struct("TestSimpleTableWithEnum");
      ds.field("color", &self.color());
      ds.finish()
  }
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq)]
pub struct TestSimpleTableWithEnumT {
  pub color: Color,
}
impl Default for TestSimpleTableWithEnumT {
  fn default() -> Self {
    Self {
      color: Color::Green,
    }
  }
}
impl TestSimpleTableWithEnumT {
  pub fn pack<'b, A: flatbuffers::Allocator + 'b>(
    &self,
    _fbb: &mut flatbuffers::FlatBufferBuilder<'b, A>
  ) -> flatbuffers::WIPOffset<TestSimpleTableWithEnum<'b>> {
    let color = self.color;
    TestSimpleTableWithEnum::create(_fbb, &TestSimpleTableWithEnumArgs{
      color,
    })
  }
}
