//
// LDASTools frameCPP - A library implementing the LIGO/Virgo frame
// specification
//
// Copyright (C) 2018 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_FrDetector_HH
#define FrameCPP_UNIVERSAL_FrDetector_HH

#if !defined( SWIGIMPORTED )
#ifndef SWIG
#include <boost/shared_ptr.hpp>
#endif /* SWIG_IMPORTED */

#include "framecpp/Universal/impl/FrDetectorClassicIO.hh"
#include "framecpp/Universal/impl/FrDetectorSerialIO.hh"
#endif /* !defined( SWIGIMPORTED ) */

#if !defined( SWIGIMPORTED )
namespace FrameCPP
{
    namespace Universal
    {
        //===================================================================
        /// \brief Detector data
        //===================================================================
        class FrDetector
#if !defined( SWIG )
            : public FrDetectorImpl::ClassicIO< FrDetector >,
              public FrDetectorImpl::SerialIO< FrDetector >
#endif /* !defined(SWIG) */
        {
        public:
#if !defined( SWIG )
            typedef boost::shared_ptr< FrDetector > FrDetectorCache_element;
#endif /* !defined(SWIG) */

            //-----------------------------------------------------------------
            /// \brief Default constructor
            ///
            /// \return
            ///     A new instance of an FrDetector object
            //-----------------------------------------------------------------
            FrDetector( );

            //-----------------------------------------------------------------
            /// \brief Constructor
            ///
            /// \param[in] Name
            ///     Instrument name
            /// \param[in] Prefix
            ///     Channel prefix for this detector
            /// \param[in] Longitude
            ///     Detector vertex longitude
            /// \param[in] Latitude
            ///     Detector vertex latitutde.
            /// \param[in] Elevation
            ///     Vertex elevation.
            /// \param[in] ArmXazimuth
            ///     Orientation of X arm.
            /// \param[in] ArmYazimuth
            ///     Orientation of Y arm.
            /// \param[in] ArmXaltitude
            ///     Altidue angle of X arm.
            /// \param[in] ArmYaltitude
            ///     Altidue angle of Y arm.
            /// \param[in] ArmXmidpoint
            ///     Distance between the detector vertex and the middle of
            ///     the X cavity.
            /// \param[in] ArmYmidpoint
            ///     Distance between the detector vertex and the middle of
            ///     the Y cavity.
            ///
            /// \return
            ///     A new instance of an FrDetector object
            //-----------------------------------------------------------------
            FrDetector(
                const name_type&             Name,
                const char*                  Prefix,
                const longitude_type         Longitude,
                const latitude_type          Latitude,
                const elevation_type         Elevation,
                const armXazimuth_type       ArmXazimuth,
                const armYazimuth_type       ArmYazimuth,
                const armXaltitude_type      ArmXaltitude,
                const armYaltitude_type      ArmYaltitude,
                const armXmidpoint_type      ArmXmidpoint,
                const armYmidpoint_type      ArmYmidpoint,
                const dataQualityOffset_type DataQualityOffset = DQO_UNSET );

            //-----------------------------------------------------------------
            /// \brief Copy constructor
            ///
            /// \param[in] detector
            ///     The source instance to copy
            ///
            /// \return
            ///     A new instance of an FrDetector object
            //-----------------------------------------------------------------
            FrDetector( const FrDetector& detector );

            const std::string& GetName( ) const;

            //-----------------------------------------------------------------
            /// \brief Retrieve detector information for static detectors
            ///
            /// \param[in] Offset
            ///     Reference the detector by its dataQualityOffset
            ///
            /// \return
            ///     An instance of an FrDetector object
            //-----------------------------------------------------------------
#if !defined( SWIG )
            static FrDetectorCache_element
            GetDetector( FrDetector::dataQualityOffsets Offset );
#endif /* !defined(SWIG) */

            //-----------------------------------------------------------------
            /// \brief Retrieve detector information for static detectors
            ///
            /// \param[in] Name
            ///     Reference the detector by its name
            ///
            /// \return
            ///     An instance of an FrDetector object
            //-----------------------------------------------------------------
            inline static FrDetectorCache_element
            GetDetector( const std::string& Name )
            {
                return ( GetDetector( GetDataQualityOffset( Name ) ) );
            }

            //-----------------------------------------------------------------
            /// \brief Merge with another FrDetector
            ///
            /// \param[in] RHS
            ///     The source of the information to append to this FrDetector
            ///     structure.
            ///
            /// \return
            ///     A reference to this object
            //-----------------------------------------------------------------
            FrDetector& Merge( const FrDetector& RHS );

            //-----------------------------------------------------------------
            /// \brief equality operator
            ///
            /// \param[in] RHS
            ///     The FrDetector object to be compared.
            ///
            /// \return
            ///     The value true is returned if the object is equivelent
            ///     to the RHS instance; false otherwise.
            //-----------------------------------------------------------------
            //-----------------------------------------------------------------
            /// \brief equality operator for abstract data type
            ///
            /// \param[in] RHS
            ///     The object to be compared.
            ///
            /// \return
            ///     The value true is returned if this object is equivelent
            ///     to the RHS instance; false otherwise.
            //-----------------------------------------------------------------
            virtual bool
            operator==( const Common::FrameSpec::Object& RHS ) const;

            /// Typed equality declared as a hidden friend, not a member, so
            /// it does not pair with the virtual operator==(Object&) override
            /// above under C++20's reversed-candidate rule.
            friend bool
            operator==( const FrDetector& LHS, const FrDetector& RHS )
            {
                return ( ( &LHS == &RHS ) ||
                         ( static_cast< const FrDetectorImpl::Data& >( LHS ) ==
                           static_cast< const FrDetectorImpl::Data& >( RHS ) ) );
            }

        private:
            //-----------------------------------------------------------------
            //-----------------------------------------------------------------
            typedef ObjectWithChecksum< Common::FrDetector > object_type;

            using Common::FrameSpec::Object::Create;

            FrDetector( istream_type& Stream );
        };
    } // namespace Universal
} // namespace FrameCPP
#endif /* ! defined(SWIGIMPORTED) */
#endif /* FrameCPP_UNIVERSAL_FrDetector_HH */
