#include "LibItsSecurity_EncdecDeclarations.hh"

#include "EtsiTs103097Codec_Certificate.hh"
#include "EtsiTs103097Codec_Data.hh"

#include "loggers.hh"

namespace LibItsSecurity__EncdecDeclarations {

  BITSTRING fx__enc__CertificateBase(IEEE1609dot2::CertificateBase const& p_cert) {
    loggers::get_instance().log_msg(">>> fx__enc__CertificateBase: ", p_cert);

    EtsiTs103097Codec_Certificate codec;
    OCTETSTRING os;
    if (codec.encode(p_cert, os) == -1) {
      loggers::get_instance().warning("fx__enc__CertificateBase: -1 result code was returned");
      return int2bit(0, 1);
    }
    
    return oct2bit(os);
  }

  INTEGER fx__dec__CertificateBase(BITSTRING& b, IEEE1609dot2::CertificateBase& p_cert) {
    loggers::get_instance().log_msg(">>> fx__dec__CertificateBase: ", b);

    EtsiTs103097Codec_Certificate codec;
    OCTETSTRING is = bit2oct(b);
    if (codec.decode(is, p_cert) == -1) {
      loggers::get_instance().warning("fx__dec__CertificateBase: -1 result code was returned");
      return -1;
    }
    
    loggers::get_instance().log_msg("<<< fx__dec__CertificateBase: ", p_cert);
    return 0;
  }
  
  BITSTRING fx__enc__ToBeSignedCertificate(const IEEE1609dot2::ToBeSignedCertificate& p) {
    return int2bit(0, 1);
  }
  
  BITSTRING fx__enc__Ieee1609Dot2Data(const IEEE1609dot2::Ieee1609Dot2Data& p) {
    loggers::get_instance().log_msg(">>> fx__enc__CertificateBase: ", p);

    return int2bit(0, 1);
  }
  
  INTEGER fx__dec__Ieee1609Dot2Data(BITSTRING& p__data, IEEE1609dot2::Ieee1609Dot2Data& p__ieee1609Dot2Data) {
    loggers::get_instance().log_msg(">>> fx__dec__Ieee1609Dot2Data: ", p__data);

    EtsiTs103097Codec_Data codec;
    OCTETSTRING is = bit2oct(p__data);
    if (codec.decode(is, p__ieee1609Dot2Data) == -1) {
      loggers::get_instance().warning("fx__dec__Ieee1609Dot2Data: -1 result code was returned");
      return -1;
    }
    
    loggers::get_instance().log_msg("<<< fx__dec__Ieee1609Dot2Data: ", p__ieee1609Dot2Data);
    return 0;
  }
  
  BITSTRING fx__enc__SspCAM(const LibItsSecurity__TypesAndValues::SspCAM& p__ssp) {
    loggers::get_instance().log_msg(">>> fx__enc__SspCAM: ", p__ssp);

    return int2bit(0, 1);
  }
  INTEGER fx__dec__SspCAM(BITSTRING& p__data, LibItsSecurity__TypesAndValues::SspCAM& p__ssp) {
    loggers::get_instance().log_msg(">>> fx__dec__SspCAM: ", p__data);

    return -1;
  }
  
  BITSTRING fx__enc__SspDENM(const LibItsSecurity__TypesAndValues::SspDENM& p__ssp) {
    loggers::get_instance().log_msg(">>> fx__enc__SspDENM: ", p__ssp);

    return int2bit(0, 1);
  }
  
  INTEGER fx__dec__SspDENM(BITSTRING& p__data, LibItsSecurity__TypesAndValues::SspDENM& p__ssp) {
    loggers::get_instance().log_msg(">>> fx__dec__SspDENM: ", p__data);

    return -1;
  }
  
} //end namespace
