#ifndef GERMANAIRLINESVA_GACONNECTOR_GATE_H
#define GERMANAIRLINESVA_GACONNECTOR_GATE_H

#include <cstdint>
#include <cstring>
#include <iostream>
#include <sstream>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>

#include "geodata.h"

namespace germanairlinesva_simdata
{
  /*
   * Representation of gate
   * Heading in degrees (0...360)
   * Radius in metres
   *
   * Designator must be null terminated
   *
   * UINT8  | CHAR[]     | POINT  | UINT8
   * -------+------------+--------+-------
   * STRLEN | DESIGNATOR | CENTER | RADIUS
   */
  class Gate
  {
    private:
      std::string designator;
      germanairlinesva_geodata::point center;
      std::uint8_t radius;
      std::vector<std::uint8_t> file;

    public:
      // From X-Plane or MakeRwys
      Gate(const std::string &designator,
           double latitude,
           double longitude,
           std::uint8_t radius);
      // From database
      Gate(const std::string &designator,
           germanairlinesva_geodata::point center,
           std::uint8_t radius);

      inline std::uint8_t *getBinaryData() { return file.data(); }
      inline std::size_t getBinaryLength() { return file.size(); }

      std::string to_string() const
      {
        std::ostringstream str;
        str << "Gate " << this->designator << " at " << this->center.latitude
            << "N " << this->center.longitude << "E, Radius "
            << (int)this->radius;
        return str.str();
      }

      friend inline std::ostream &operator<<(std::ostream &os, const Gate &gate)
      {
        return os << gate.to_string();
      }
  };
} // namespace germanairlinesva_simdata

#endif