//
// LDASTools frameCPP - A library implementing the LIGO/Virgo frame
// specification
//
// Copyright (C) 2018-2020 California Institute of Technology
//
// LDASTools frameCPP is free software; you may redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 (GPLv2) of the
// License or at your discretion, any later version.
//
// LDASTools frameCPP is distributed in the hope that it will be useful, but
// without any warranty or even the implied warranty of merchantability
// or fitness for a particular purpose. See the GNU General Public
// License (GPLv2) for more details.
//
// Neither the names of the California Institute of Technology (Caltech),
// The Massachusetts Institute of Technology (M.I.T), The Laser
// Interferometer Gravitational-Wave Observatory (LIGO), nor the names
// of its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// You should have received a copy of the licensing terms for this
// software included in the file LICENSE located in the top-level
// directory of this package. If you did not, you can view a copy at
// http://dcc.ligo.org/M1500244/LICENSE
//

#ifndef FrameCPP_UNIVERSAL__IMPL__FrSimDataData_HH
#define FrameCPP_UNIVERSAL__IMPL__FrSimDataData_HH

#if defined( __cplusplus ) && !defined( SWIG )

#endif /* defined( __cplusplus ) && !defined( SWIG ) */

#undef FR_SIM_DATA_NAME_TYPE
#if defined( __cplusplus )
#define FR_SIM_DATA_NAME_TYPE std::string
#endif /* defined(__cplusplus) */

#undef FR_SIM_DATA_COMMENT_TYPE
#if defined( __cplusplus )
#define FR_SIM_DATA_COMMENT_TYPE std::string
#endif /* defined(__cplusplus) */

#undef FR_SIM_DATA_SAMPLERATE_TYPE
#define FR_SIM_DATA_SAMPLERATE_TYPE REAL_8

#undef FR_SIM_DATA_TIMEOFFSEST_TYPE
#define FR_SIM_DATA_TIMEOFFSET_TYPE REAL_8

#undef FR_SIM_DATA_FSHIFT_TYPE
#define FR_SIM_DATA_FSHIFT_TYPE REAL_8

#undef FR_SIM_DATA_PHASE_TYPE
#define FR_SIM_DATA_PHASE_TYPE REAL_4

#if defined( __cplusplus ) && !defined( SWIG )

#include "framecpp/Common/SearchContainer.hh"

#include "framecpp/Universal/FrTable.hh"
#include "framecpp/Universal/FrVect.hh"

#include "framecpp/Universal/impl/FrObjectMetaData.hh"

namespace FrameCPP
{
    namespace Universal
    {
        namespace FrSimDataImpl
        {
            class Data : public Impl::FrObjectMetaData< Data >
            {
            public:
                struct v3
                {
                    using name_type = std::string;
                    using comment_type = std::string;
                    using sampleRate_type = REAL_4;

                    using data_type = Common::Container< FrVect >;
                    using iterator = data_type::iterator;
                    using const_iterator = data_type::const_iterator;

                    using input_type =
                        Common::SearchContainer< FrVect, &FrVect::GetName >;
                    using input_iterator = input_type::iterator;
                    using const_input_iterator = input_type::const_iterator;
                };
                struct v4
                {
                    using name_type = v3::name_type;
                    using comment_type = v3::comment_type;
                    using sampleRate_type = v3::sampleRate_type;

                    using data_type = v3::data_type;
                    using iterator = v3::iterator;
                    using const_iterator = v3::const_iterator;

                    using input_type = v3::input_type;
                    using input_iterator = v3::input_iterator;
                    using const_input_iterator = v3::const_input_iterator;

                    using table_type =
                        Common::SearchContainer< FrTable,
                                                 &FrTable::GetNameSlow >;
                    using table_iterator = table_type::iterator;
                    using const_table_iterator = table_type::const_iterator;
                };
                struct v5
                {
                    using name_type = v4::name_type;
                    using comment_type = v4::comment_type;
                    using sampleRate_type = v4::sampleRate_type;
                    using timeOffset_type = REAL_8;
                    using fShift_type = REAL_8;
                    using phase_type = REAL_4;

                    using data_type = v4::data_type;
                    using iterator = v4::iterator;
                    using const_iterator = v4::const_iterator;

                    using input_type = v4::input_type;
                    using input_iterator = v4::input_iterator;
                    using const_input_iterator = v4::const_input_iterator;

                    using table_type = v4::table_type;
                    using table_iterator = v4::table_iterator;
                    using const_table_iterator = v4::const_table_iterator;
                };
                using v6 = v5;
                struct v7
                {
                    using name_type = v6::name_type;
                    using comment_type = v6::comment_type;
                    using sampleRate_type = REAL_8;
                    using timeOffset_type = v6::timeOffset_type;
                    using fShift_type = v6::fShift_type;
                    using phase_type = v6::phase_type;

                    using data_type = v6::data_type;
                    using iterator = v6::iterator;
                    using const_iterator = v6::const_iterator;

                    using input_type = v6::input_type;
                    using input_iterator = v6::input_iterator;
                    using const_input_iterator = v6::const_input_iterator;

                    using table_type = v6::table_type;
                    using table_iterator = v6::table_iterator;
                    using const_table_iterator = v6::const_table_iterator;
                };
                using v8 = v7;
                using v9 = v8;

                using current_version = v9;

                using name_type = current_version::name_type;
                using comment_type = current_version::comment_type;
                using sampleRate_type = current_version::sampleRate_type;
                using timeOffset_type = current_version::timeOffset_type;
                using fShift_type = current_version::fShift_type;
                using phase_type = current_version::phase_type;

                using data_type = current_version::data_type;
                using iterator = current_version::iterator;
                using const_iterator = current_version::const_iterator;

                using input_type = current_version::input_type;
                using input_iterator = current_version::input_iterator;
                using const_input_iterator =
                    current_version::const_input_iterator;

                using table_type = current_version::table_type;
                using table_iterator = current_version::table_iterator;
                using const_table_iterator =
                    current_version::const_table_iterator;

                constexpr static timeOffset_type DEFAULT_TIME_OFFSET{ 0 };

                inline const name_type&
                GetName( ) const
                {
                    return ( name );
                }

                inline const comment_type&
                GetComment( ) const
                {
                    return ( comment );
                }

                inline sampleRate_type
                GetSampleRate( ) const
                {
                    return ( sampleRate );
                }

                inline timeOffset_type
                GetTimeOffset( ) const
                {
                    return ( timeOffset );
                }

                inline fShift_type
                GetFShift( ) const
                {
                    return ( fShift );
                }

                inline phase_type
                GetPhase( ) const
                {
                    return ( phase );
                }

                //-----------------------------------------------------------------
                /// \brief Establish the value of the comment field.
                ///
                /// \param[in] Comment
                ///     The desired value of the comment field.
                //-----------------------------------------------------------------
                inline void
                SetComment( const comment_type& Comment )
                {
                    comment = Comment;
                }

                //-----------------------------------------------------------------
                /// \brief Establish the value of the sampleRate field.
                ///
                /// \param[in] SampleRate
                ///     The desired value of the sampleRate field.
                //-----------------------------------------------------------------
                inline void
                SetSampleRate( sampleRate_type SampleRate )
                {
                    sampleRate = SampleRate;
#if WORKING
                    //-----------------------------------------------------------------
                    /// \todo
                    /// Modifications to the sample rate need also be reflected
                    /// in the corrisponding FrVect structures.
                    //-----------------------------------------------------------------
                    for ( fr_sim_data_data_type::iterator
                              cur = RefData( ).begin( ),
                              last = RefData( ).end( );
                          cur != last;
                          ++cur )
                    {
                        cur->
                    }
#endif /* WORKING */
                }

                //-----------------------------------------------------------------
                /// \brief Establish the value of the timeOffset field.
                ///
                /// \param[in] Time
                ///     The desired value of the timeOffset field.
                //-----------------------------------------------------------------
                inline void
                SetTimeOffset( timeOffset_type TimeOffset )
                {
                    timeOffset = TimeOffset;
                }

                inline const data_type&
                RefData( ) const
                {
                    return data;
                }

                inline data_type&
                RefData( )
                {
                    return data;
                }

                inline const input_type&
                RefInput( ) const
                {
                    return input;
                }

                inline input_type&
                RefInput( )
                {
                    return input;
                }

                inline const table_type&
                RefTable( ) const
                {
                    return table;
                }

                inline table_type&
                RefTable( )
                {
                    return table;
                }

                inline bool
                operator==( const Data& RHS ) const
                {
                    return ( ( this == &RHS ) ||
                             ( ( name.compare( RHS.name ) == 0 ) &&
                               ( comment.compare( RHS.comment ) == 0 ) &&
                               ( sampleRate == RHS.sampleRate ) &&
                               ( timeOffset == RHS.timeOffset ) &&
                               ( fShift == RHS.fShift ) &&
                               ( phase == RHS.phase ) ) );
                }

            protected:
                //-------------------------------------------------------
                /// Name of simulated data
                //-------------------------------------------------------
                name_type name;
                //-------------------------------------------------------
                /// Comment
                //-------------------------------------------------------
                comment_type comment;
                //-------------------------------------------------------
                /// Simulated data sample rate, samples/s
                //-------------------------------------------------------
                sampleRate_type sampleRate;
                //-------------------------------------------------------
                /// Offset of 1st sample relative to the frame start time
                //-------------------------------------------------------
                timeOffset_type timeOffset;
                //-------------------------------------------------------
                /// fShift is the frequency in the original data
                //-------------------------------------------------------
                fShift_type fShift;
                //-------------------------------------------------------
                /// Phase of hetrodyning signal at start of dataset.
                //-------------------------------------------------------
                phase_type phase;

                data_type  data;
                input_type input;
                table_type table;
                //=======================================================
                //-------------------------------------------------------
                static constexpr unsigned int MAX_REF{ 3 };
            }; // class Data
        } // namespace FrSimDataImpl
    } // namespace Universal
} // namespace FrameCPP

FR_OBJECT_META_DATA_DECLARE_UNIVERSAL( FrSimDataImpl )

#endif /* defined( __cplusplus ) && !defined( SWIG ) */

#endif /* FrameCPP_UNIVERSAL__IMPL__FrSimDataData_HH */
