
#include "hark-lib/tf.h"

namespace hark
{
    std::ostream &
    Position::write(std::ostream &os) const
    {
        std::stringstream ss_channels;
        ss_channels << "[";
        for(int i = 0; i < channels.size(); i++){
            if(i != 0){ ss_channels << ", "; }
            ss_channels << this->channels[i];
        }
        ss_channels << "]";

        os << "{"
           << "id: " << this->id
           << ", sys: " << ((this->sys == TF_Coordinate::Polar) ? "Polar" : "Cartesian")
           << ", coord: [" << this->coord[0] << ", " << this->coord[1] << ", " << this->coord[2] << "]"
           << ", path: " << this->path
           << ", data: " << this->data
           << ", channelsUse: " << this->channelsUse
           << ", channels: " << ss_channels.str()
           << "}";
        return os;
    }

    std::ostream &
    Neighbor::write(std::ostream &os) const
    {
        std::stringstream ss_ids, ss_neighbors, ss_poses;
        ss_ids << "[";
        for(int i = 0; i < ids.size(); i++){
            if(i != 0){ ss_ids << ", "; }
            ss_ids << ids[i];
        }
        ss_ids << "]";
        ss_neighbors << "[";
        for(std::vector<std::vector<int> >::const_iterator it = this->neighbors.begin(); it != this->neighbors.end(); ++it){
            if(it != this->neighbors.begin()){ ss_neighbors << ", "; }
            ss_neighbors << "[";
            for(std::vector<int>::const_iterator it2 = it->begin(); it2 != it->end(); ++it2){
                if(it2 != it->begin()){ ss_neighbors << ", "; }
                ss_neighbors << *it2;
            }
            ss_neighbors << "]";
        }
        ss_neighbors << "]";
        ss_poses << "[";
        for(std::vector<std::vector<Position> >::const_iterator it = this->poses.begin(); it != this->poses.end(); ++it){
            if(it != this->poses.begin()){ ss_poses << ", "; }
            ss_poses << "[";
            for(std::vector<Position>::const_iterator it2 = it->begin(); it2 != it->end(); ++it2){
                if(it2 != it->begin()){ ss_poses << ", "; }
                ss_poses << *it2;
            }
            ss_poses << "]";
        }
        ss_poses << "]";

        os << "{"
           << "ids: " << ss_ids.str()
           << ", neighbors: " << ss_neighbors.str()
           << ", poses: " << ss_poses.str()
           << ", alg: " << ((this->alg == TF_NeighborAlgorithm::Undefined) ? "Undefined" : "NearestNeighbor")
           << "}";
        return os;
    }

    std::ostream &
    Config::write(std::ostream &os) const
    {
        os << "{"
           << "comment: " << this->comment
           << ", synchronousAverage: " << this->synchronousAverage
           << ", TSPpath: " << this->TSPpath
           << ", TSPoffset: " << this->TSPoffset
           << ", TSPLength: " << this->TSPLength
           << ", peakSearchFrom: " << this->peakSearchFrom
           << ", peakSearchTo: " << this->peakSearchTo
           << ", nfft: " << this->nfft
           << ", samplingRate: " << this->samplingRate
           << ", signalMax: " << this->signalMax
           << "}";
        return os;
    }

    std::ostream &
    TransferFunction::write(std::ostream &os) const
    {
        std::stringstream ss_sources, ss_microphones, ss_localization, ss_separation;
        ss_sources << "[";
        for(std::vector<Position>::const_iterator it = this->m_Sources.begin(); it != this->m_Sources.end(); ++it){
            if(it != this->m_Sources.begin()){ ss_sources << ", "; }
            ss_sources << *it;
        }
        ss_sources << "]";
        ss_microphones << "[";
        for(std::vector<Position>::const_iterator it = this->m_Microphones.begin(); it != this->m_Microphones.end(); ++it){
            if(it != this->m_Microphones.begin()){ ss_microphones << ", "; }
            ss_microphones << *it;
        }
        ss_microphones << "]";
        ss_localization << "{";
        for(std::map<int, Matrix<std::complex<float> > >::const_iterator it = this->m_Localization.begin(); it != this->m_Localization.end(); ++it){
            if(it != this->m_Localization.begin()){ ss_localization << ", "; }
            ss_localization << it->first << ": " << it->second;
        }
        ss_localization << "}";
        ss_separation << "{";
        for(std::map<int, Matrix<std::complex<float> > >::const_iterator it = this->m_Separation.begin(); it != this->m_Separation.end(); ++it){
            if(it != this->m_Separation.begin()){ ss_separation << ", "; }
            ss_separation << it->first << ": " << it->second;
        }
        ss_separation << "}";

        os << "{"
           << "is_valid: " << this->is_valid
           << ", m_WhatIsThis: " << this->m_WhatIsThis
           << ", m_Sources: " << ss_sources.str()
           << ", m_Neighbors: " << this->m_Neighbors
           << ", m_Microphones: " << ss_microphones.str()
           << ", m_Config: " << this->m_Config
           << ", m_Localization: " << ss_localization.str()
           << ", m_Separation: " << ss_separation.str()
           << "}";
        return os;
    }
} // namespace hark end

/* end of file */
