/*
 * Copyright 2020 Free Software Foundation, Inc.
 *
 * This file is part of GNU Radio
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 */

/***********************************************************************************/
/* This file is automatically generated using bindtool and can be manually edited  */
/* The following lines can be configured to regenerate this file during cmake      */
/* If manual edits are made, the following tags should be modified accordingly.    */
/* BINDTOOL_GEN_AUTOMATIC(0)                                                       */
/* BINDTOOL_USE_PYGCCXML(0)                                                        */
/* BINDTOOL_HEADER_FILE(generic_encoder.h)                                         */
/* BINDTOOL_HEADER_FILE_HASH(4bf764edbc6d2d3d99af4d2a65417344)                     */
/***********************************************************************************/

#include <pybind11/complex.h>
#include <pybind11/numpy.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

namespace py = pybind11;

#include <gnuradio/fec/generic_encoder.h>
// pydoc.h is automatically generated in the build directory
#include <generic_encoder_pydoc.h>

void bind_generic_encoder(py::module& m)
{

    using generic_encoder = ::gr::fec::generic_encoder;


    py::class_<generic_encoder, std::shared_ptr<generic_encoder>>(
        m, "generic_encoder", D(generic_encoder))

        // .def(py::init<>(),D(generic_encoder,generic_encoder,0))
        // .def(py::init<std::string>(),           py::arg("name"),
        //    D(generic_encoder,generic_encoder,1)
        // )
        // .def(py::init<gr::fec::generic_encoder const &>(),           py::arg("arg0"),
        //    D(generic_encoder,generic_encoder,2)
        // )


        .def("generic_work",
             &generic_encoder::generic_work,
             py::arg("in_buffer"),
             py::arg("out_buffer"),
             D(generic_encoder, generic_work))


        .def("unique_id", &generic_encoder::unique_id, D(generic_encoder, unique_id))


        .def("alias", &generic_encoder::alias, D(generic_encoder, alias))


        .def("rate", &generic_encoder::rate, D(generic_encoder, rate))


        .def("get_input_size",
             &generic_encoder::get_input_size,
             D(generic_encoder, get_input_size))


        .def("get_output_size",
             &generic_encoder::get_output_size,
             D(generic_encoder, get_output_size))


        .def("get_input_conversion",
             &generic_encoder::get_input_conversion,
             D(generic_encoder, get_input_conversion))


        .def("get_output_conversion",
             &generic_encoder::get_output_conversion,
             D(generic_encoder, get_output_conversion))


        .def("set_frame_size",
             &generic_encoder::set_frame_size,
             py::arg("frame_size"),
             D(generic_encoder, set_frame_size))

        .def("encode",
             [](generic_encoder& self,
                const py::array_t<unsigned char,
                                  py::array::c_style | py::array::forcecast>& array) {
                 py::buffer_info inb = array.request();
                 if (inb.ndim != 1) {
                     throw std::runtime_error("Only ONE-dimensional vectors allowed!");
                 }
                 if (inb.size != self.get_input_size()) {
                     throw std::runtime_error("Input vector size != input_size!");
                 }
                 auto result = py::array_t<unsigned char>(self.get_output_size());
                 py::buffer_info resb = result.request();

                 self.generic_work((const unsigned char*)inb.ptr,
                                   (unsigned char*)resb.ptr);
                 return result;
             })

        ;


    m.def("get_encoder_output_size",
          &::gr::fec::get_encoder_output_size,
          py::arg("my_encoder"),
          D(get_encoder_output_size));


    m.def("get_encoder_input_size",
          &::gr::fec::get_encoder_input_size,
          py::arg("my_encoder"),
          D(get_encoder_input_size));


    m.def("get_encoder_input_conversion",
          &::gr::fec::get_encoder_input_conversion,
          py::arg("my_encoder"),
          D(get_encoder_input_conversion));


    m.def("get_encoder_output_conversion",
          &::gr::fec::get_encoder_output_conversion,
          py::arg("my_encoder"),
          D(get_encoder_output_conversion));
}
