use super::{Attribute, Comment, Identifier, Span, WithAttributes, WithDocumentation, WithIdentifier, WithSpan};
use serde::{Deserialize, Serialize};

/// An enum declaration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Enum {
  /// The name of the enum.
  pub name: Identifier,
  /// The values of the enum.
  pub values: Vec<EnumValue>,
  /// The attributes of this enum.
  pub attributes: Vec<Attribute>,
  /// The comments for this enum.
  pub documentation: Option<Comment>,
  /// The location of this enum in the text representation.
  pub span: Span,
}

impl WithIdentifier for Enum {
  fn identifier(&self) -> &Identifier {
    &self.name
  }
}

impl WithSpan for Enum {
  fn span(&self) -> &Span {
    &self.span
  }
}

impl WithAttributes for Enum {
  fn attributes(&self) -> &[Attribute] {
    &self.attributes
  }
}

impl WithDocumentation for Enum {
  fn documentation(&self) -> &Option<Comment> {
    &self.documentation
  }

  fn is_commented_out(&self) -> bool {
    false
  }
}

/// An enum value definition.
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct EnumValue {
  /// The name of the enum value as it will be exposed by the api.
  pub name: Identifier,
  pub attributes: Vec<Attribute>,
  pub documentation: Option<Comment>,
  /// The location of this enum value in the text representation.
  pub span: Span,
  pub commented_out: bool,
}

impl WithIdentifier for EnumValue {
  fn identifier(&self) -> &Identifier {
    &self.name
  }
}

impl WithAttributes for EnumValue {
  fn attributes(&self) -> &[Attribute] {
    &self.attributes
  }
}

impl WithSpan for EnumValue {
  fn span(&self) -> &Span {
    &self.span
  }
}
