/*
 *  This file was autogenerated by the GPUdb schema processor.
 *
 *  DO NOT EDIT DIRECTLY.
 */
#ifndef __CREATE_MATERIALIZED_VIEW_H__
#define __CREATE_MATERIALIZED_VIEW_H__

namespace gpudb
{

    /**
     * A set of input parameters for {@link
     * #createMaterializedView(const CreateMaterializedViewRequest&) const}.
     * <p>
     * Initiates the process of creating a materialized view, reserving the
     * view's name to prevent other views or tables from being created with
     * that name.
     * <p>
     * For materialized view details and examples, see
     * <a href="../../../concepts/materialized_views/"
     * target="_top">Materialized Views</a>.
     * <p>
     * The response contains @a viewId, which is used to tag each subsequent
     * operation (projection, union, aggregation, filter, or join) that will
     * compose
     * the view.
     */
    struct CreateMaterializedViewRequest
    {

        /**
         * Constructs a CreateMaterializedViewRequest object with default
         * parameter values.
         */
        CreateMaterializedViewRequest() :
            tableName(std::string()),
            options(std::map<std::string, std::string>())
        {
        }

        /**
         * Constructs a CreateMaterializedViewRequest object with the specified
         * parameters.
         * 
         * @param[in] tableName_  Name of the table to be created that is the
         *                        top-level table of the materialized view, in
         *                        [schema_name.]table_name format, using
         *                        standard <a
         *                        href="../../../concepts/tables/#table-name-resolution"
         *                        target="_top">name resolution rules</a> and
         *                        meeting <a
         *                        href="../../../concepts/tables/#table-naming-criteria"
         *                        target="_top">table naming criteria</a>.
         * @param[in] options_  Optional parameters.
         *                      <ul>
         *                              <li>
         *                      gpudb::create_materialized_view_collection_name:
         *                      [DEPRECATED--please specify the containing
         *                      schema for the materialized view as part of @a
         *                      tableName and use /create/schema to create the
         *                      schema if non-existent]  Name of a schema which
         *                      is to contain the newly created view. If the
         *                      schema provided is non-existent, it will be
         *                      automatically created.
         *                              <li>
         *                      gpudb::create_materialized_view_ttl: Sets the
         *                      <a href="../../../concepts/ttl/"
         *                      target="_top">TTL</a> of the table specified in
         *                      @a tableName.
         *                              <li>
         *                      gpudb::create_materialized_view_persist: If @a
         *                      true, then the materialized view specified in
         *                      @a tableName will be persisted and will not
         *                      expire unless a @a ttl is specified.   If @a
         *                      false, then the materialized view will be an
         *                      in-memory table and will expire unless a @a ttl
         *                      is specified otherwise.
         *                      <ul>
         *                              <li>
         *                      gpudb::create_materialized_view_true
         *                              <li>
         *                      gpudb::create_materialized_view_false
         *                      </ul>
         *                      The default value is
         *                      gpudb::create_materialized_view_false.
         *                              <li>
         *                      gpudb::create_materialized_view_refresh_method:
         *                      Method by which the join can be refreshed when
         *                      the data in underlying member tables have
         *                      changed.
         *                      <ul>
         *                              <li>
         *                      gpudb::create_materialized_view_manual: Refresh
         *                      only occurs when manually requested by calling
         *                      /alter/table with an 'action' of 'refresh'
         *                              <li>
         *                      gpudb::create_materialized_view_on_query:
         *                      Refresh any time the view is queried.
         *                              <li>
         *                      gpudb::create_materialized_view_on_change: If
         *                      possible, incrementally refresh (refresh just
         *                      those records added) whenever an insert,
         *                      update, delete or refresh of input table is
         *                      done.  A full refresh is done if an incremental
         *                      refresh is not possible.
         *                              <li>
         *                      gpudb::create_materialized_view_periodic:
         *                      Refresh table periodically at rate specified by
         *                      @a refresh_period
         *                      </ul>
         *                      The default value is
         *                      gpudb::create_materialized_view_manual.
         *                              <li>
         *                      gpudb::create_materialized_view_refresh_period:
         *                      When @a refresh_method is @a periodic,
         *                      specifies the period in seconds at which
         *                      refresh occurs
         *                              <li>
         *                      gpudb::create_materialized_view_refresh_start_time:
         *                      When @a refresh_method is @a periodic,
         *                      specifies the first time at which a refresh is
         *                      to be done.  Value is a datetime string with
         *                      format 'YYYY-MM-DD HH:MM:SS'.
         *                              <li>
         *                      gpudb::create_materialized_view_execute_as:
         *                      User name to use to run the refresh job
         *                      </ul>
         * 
         */
        CreateMaterializedViewRequest(const std::string& tableName_, const std::map<std::string, std::string>& options_):
            tableName( tableName_ ),
            options( options_ )
        {
        }

        std::string tableName;
        std::map<std::string, std::string> options;
    };
}

namespace avro
{
    template<> struct codec_traits<gpudb::CreateMaterializedViewRequest>
    {
        static void encode(Encoder& e, const gpudb::CreateMaterializedViewRequest& v)
        {
            ::avro::encode(e, v.tableName);
            ::avro::encode(e, v.options);
        }

        static void decode(Decoder& d, gpudb::CreateMaterializedViewRequest& v)
        {
            if (::avro::ResolvingDecoder *rd = dynamic_cast< ::avro::ResolvingDecoder*>(&d))
            {
                const std::vector<size_t> fo = rd->fieldOrder();

                for (std::vector<size_t>::const_iterator it = fo.begin(); it != fo.end(); ++it)
                {
                    switch (*it)
                    {
                        case 0:
                            ::avro::decode(d, v.tableName);
                            break;

                        case 1:
                            ::avro::decode(d, v.options);
                            break;

                        default:
                            break;
                    }
                }
            }
            else
            {
                ::avro::decode(d, v.tableName);
                ::avro::decode(d, v.options);
            }
        }
    };
}

namespace gpudb
{

    /**
     * A set of output parameters for {@link
     * #createMaterializedView(const CreateMaterializedViewRequest&) const}.
     * <p>
     * Initiates the process of creating a materialized view, reserving the
     * view's name to prevent other views or tables from being created with
     * that name.
     * <p>
     * For materialized view details and examples, see
     * <a href="../../../concepts/materialized_views/"
     * target="_top">Materialized Views</a>.
     * <p>
     * The response contains @a viewId, which is used to tag each subsequent
     * operation (projection, union, aggregation, filter, or join) that will
     * compose
     * the view.
     */
    struct CreateMaterializedViewResponse
    {

        /**
         * Constructs a CreateMaterializedViewResponse object with default
         * parameter values.
         */
        CreateMaterializedViewResponse() :
            tableName(std::string()),
            viewId(std::string()),
            info(std::map<std::string, std::string>())
        {
        }

        std::string tableName;
        std::string viewId;
        std::map<std::string, std::string> info;
    };
}

namespace avro
{
    template<> struct codec_traits<gpudb::CreateMaterializedViewResponse>
    {
        static void encode(Encoder& e, const gpudb::CreateMaterializedViewResponse& v)
        {
            ::avro::encode(e, v.tableName);
            ::avro::encode(e, v.viewId);
            ::avro::encode(e, v.info);
        }

        static void decode(Decoder& d, gpudb::CreateMaterializedViewResponse& v)
        {
            if (::avro::ResolvingDecoder *rd = dynamic_cast< ::avro::ResolvingDecoder*>(&d))
            {
                const std::vector<size_t> fo = rd->fieldOrder();

                for (std::vector<size_t>::const_iterator it = fo.begin(); it != fo.end(); ++it)
                {
                    switch (*it)
                    {
                        case 0:
                            ::avro::decode(d, v.tableName);
                            break;

                        case 1:
                            ::avro::decode(d, v.viewId);
                            break;

                        case 2:
                            ::avro::decode(d, v.info);
                            break;

                        default:
                            break;
                    }
                }
            }
            else
            {
                ::avro::decode(d, v.tableName);
                ::avro::decode(d, v.viewId);
                ::avro::decode(d, v.info);
            }
        }
    };
}

#endif
