/**
 * Copyright (C) 2013 Regents of the University of California.
 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
 * See COPYING for copyright and distribution information.
 */

#include <stdexcept>
#include "common.hpp"
#include "interest.hpp"

using namespace std;

namespace ndn {
  
void Exclude::get(struct ndn_Exclude& excludeStruct) const
{
  if (excludeStruct.maxEntries < entries_.size())
    throw runtime_error("excludeStruct.maxEntries must be >= this exclude getEntryCount()");
  
  excludeStruct.nEntries = entries_.size();
  for (unsigned int i = 0; i < excludeStruct.nEntries; ++i)
    entries_[i].get(excludeStruct.entries[i]);  
}

void Exclude::set(const struct ndn_Exclude& excludeStruct)
{
  entries_.clear();
  for (unsigned int i = 0; i < excludeStruct.nEntries; ++i) {
    ndn_ExcludeEntry *entry = &excludeStruct.entries[i];
    
    if (entry->type == ndn_Exclude_COMPONENT)
      addComponent(entry->component.value, entry->component.valueLength);
    else if (entry->type == ndn_Exclude_ANY)
      addAny();
    else
      throw runtime_error("unrecognized ndn_ExcludeType");
  }
}

string Exclude::toUri() const
{
	if (entries_.size() == 0)
		return "";

  ostringstream result;
  for (unsigned i = 0; i < entries_.size(); ++i) {
    if (i > 0)
      result << ",";
        
    if (entries_[i].getType() == ndn_Exclude_ANY)
      result << "*";
    else
      Name::toEscapedString(*entries_[i].getComponent().getValue(), result);
  }
  
  return result.str();  
}

void Interest::set(const struct ndn_Interest& interestStruct) 
{
  name_.set(interestStruct.name);
  minSuffixComponents_ = interestStruct.minSuffixComponents;
  maxSuffixComponents_ = interestStruct.maxSuffixComponents;
  
  publisherPublicKeyDigest_.set(interestStruct.publisherPublicKeyDigest);
  
  exclude_.set(interestStruct.exclude);
  childSelector_ = interestStruct.childSelector;
  answerOriginKind_ = interestStruct.answerOriginKind;
  scope_ = interestStruct.scope;
  interestLifetimeMilliseconds_ = interestStruct.interestLifetimeMilliseconds;
  nonce_ = Blob(interestStruct.nonce, interestStruct.nonceLength);
}

void Interest::get(struct ndn_Interest& interestStruct) const 
{
  name_.get(interestStruct.name);
  interestStruct.minSuffixComponents = minSuffixComponents_;
  interestStruct.maxSuffixComponents = maxSuffixComponents_;
  publisherPublicKeyDigest_.get(interestStruct.publisherPublicKeyDigest);
  exclude_.get(interestStruct.exclude);
  interestStruct.childSelector = childSelector_;
  interestStruct.answerOriginKind = answerOriginKind_;
  interestStruct.scope = scope_;
  interestStruct.interestLifetimeMilliseconds = interestLifetimeMilliseconds_;

  interestStruct.nonceLength = nonce_.size();
  if (nonce_.size() > 0)
    interestStruct.nonce = (unsigned char *)nonce_.buf();
  else
    interestStruct.nonce = 0;
}
  
}

