// Interface exposed to emscripten's WebIDL Binder.
// http://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_and_javascript/WebIDL-Binder.html
enum draco_GeometryAttribute_Type {
  "draco_GeometryAttribute::INVALID",
  "draco_GeometryAttribute::POSITION",
  "draco_GeometryAttribute::NORMAL",
  "draco_GeometryAttribute::COLOR",
  "draco_GeometryAttribute::TEX_COORD",
  "draco_GeometryAttribute::GENERIC"
};

[Prefix="draco::"]
interface GeometryAttribute {
  void GeometryAttribute();
};

enum draco_EncodedGeometryType {
  "draco::INVALID_GEOMETRY_TYPE",
  "draco::POINT_CLOUD",
  "draco::TRIANGULAR_MESH"
};

enum draco_MeshEncoderMethod {
  "draco::MESH_SEQUENTIAL_ENCODING",
  "draco::MESH_EDGEBREAKER_ENCODING"
};

[Prefix="draco::"]
interface PointAttribute {
  void PointAttribute();
  long size();

  // From GeometryAttribute
  long attribute_type();
  long data_type();
  byte num_components();
  boolean normalized();
  long byte_stride();
  long byte_offset();
  long unique_id();
};

[Prefix="draco::"]
interface PointCloud {
  void PointCloud();

  long num_attributes();
  long num_points();
};

[Prefix="draco::"]
interface Mesh : PointCloud {
  void Mesh();
  long num_faces();

  // From PointCloud
  long num_attributes();
  long num_points();
  void set_num_points(long num_points);
};

[Prefix="draco::"]
interface Metadata {
  void Metadata();
};

// TODO(zhafang): Move DracoTypedArray to be shared between encoder and decoder
// Draco version of typed arrays. The memory of these arrays is allocated on the
// emscripten heap.
interface DracoFloat32Array {
  void DracoFloat32Array();
  float GetValue(long index);
  long size();
};

interface DracoInt8Array {
  void DracoInt8Array();
  long GetValue(long index);
  long size();
};

interface MetadataBuilder {
  void MetadataBuilder();

  boolean AddStringEntry(Metadata metadata,
                         [Const] DOMString entry_name,
                         [Const] DOMString entry_value);
  boolean AddIntEntry(Metadata metadata,
                      [Const] DOMString entry_name,
                      long entry_value);
  boolean AddDoubleEntry(Metadata metadata,
                         [Const] DOMString entry_name,
                         double entry_value);
};

interface MeshBuilder {
  void MeshBuilder();

  boolean AddFacesToMesh(Mesh mesh, long num_faces, [Const] long[] faces);
  long AddFloatAttributeToMesh(Mesh mesh, draco_GeometryAttribute_Type type,
                               long num_vertices, long num_components,
                               [Const] float[] att_values);
  boolean SetMetadataForAttribute(Mesh mesh, long attribute_id,
                                  [Const] Metadata metadata);
  boolean AddMetadataToMesh(Mesh mesh, [Const] Metadata metadata);
};

interface Encoder {
  void Encoder();
  void SetEncodingMethod(draco_MeshEncoderMethod method);
  void SetAttributeQuantization(draco_GeometryAttribute_Type type,
                                long quantization_bits);
  void SetAttributeExplicitQuantization(draco_GeometryAttribute_Type type,
                                        long quantization_bits,
                                        long num_components,
                                        [Const] float[] origin,
                                        float range);
  void SetSpeedOptions(long encoding_speed, long decoding_speed);
  long EncodeMeshToDracoBuffer(Mesh mesh,
                               DracoInt8Array encoded_data);
};
