/* ----------------------------------------------------------------------------
 * This file was automatically generated by SWIG (http://www.swig.org).
 * Version 1.3.35
 *
 * Do not make changes to this file unless you know what you are doing--modify
 * the SWIG interface file instead.
 * ----------------------------------------------------------------------------- */

namespace be.portugal.eid {

using System;
using System.Runtime.InteropServices;

/// <summary>Container class for all certificates on the card.</summary>
public class PTEID_Certificates : PTEID_Crypto {
  private HandleRef swigCPtr;

  internal PTEID_Certificates(IntPtr cPtr, bool cMemoryOwn) : base(pteidlib_dotNetPINVOKE.PTEID_CertificatesUpcast(cPtr), cMemoryOwn) {
    swigCPtr = new HandleRef(this, cPtr);
  }

  internal static HandleRef getCPtr(PTEID_Certificates obj) {
    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
  }

  ~PTEID_Certificates() {
    Dispose();
  }

  public override void Dispose() {
    lock(this) {
      if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
        swigCMemOwn = false;
        pteidlib_dotNetPINVOKE.delete_PTEID_Certificates(swigCPtr);
      }
      swigCPtr = new HandleRef(null, IntPtr.Zero);
      GC.SuppressFinalize(this);
      base.Dispose();
    }
  }

  /// <summary>
  /// Create an PTEID_Certificates store without any link to a card.
  /// </summary>
  /// <remarks>
  /// This store is not link to any Card, so some methods could not be used.
  /// These methods throw PTEID_ExBadUsage exception.
  /// </remarks>
  public PTEID_Certificates()
      : this(pteidlib_dotNetPINVOKE.new_PTEID_Certificates(), true)
  {
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
  }

  /// <summary>The number of certificates on the card.</summary>
  public uint countFromCard()
  {
    uint ret = pteidlib_dotNetPINVOKE.PTEID_Certificates_countFromCard(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>The number of certificates (on the card or not).</summary>
  public uint countAll()
  {
    uint ret = pteidlib_dotNetPINVOKE.PTEID_Certificates_countAll(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>
  /// Get the ulIndex certificate from the card.
  /// </summary>
  /// <remarks>
  /// Throw PTEID_ExParamRange exception if the index is out of range.
  /// </remarks>
  public PTEID_Certificate getCertFromCard(uint ulIndexCard)
  {
    PTEID_Certificate ret = new PTEID_Certificate(pteidlib_dotNetPINVOKE.PTEID_Certificates_getCertFromCard(swigCPtr, ulIndexCard), false);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>
  /// Return the certificate with the number ulIndexAll.
  /// ATTENTION ulIndexAll and ulIndexCard are two different index.
  /// Index will change if new certificates are added with addCert().
  /// </summary>
  public PTEID_Certificate getCert(uint ulIndexAll)
  {
    PTEID_Certificate ret = new PTEID_Certificate(pteidlib_dotNetPINVOKE.PTEID_Certificates_getCert__SWIG_0(swigCPtr, ulIndexAll), false);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Return the certificate by type.</summary>
  public PTEID_Certificate getCert(PTEID_CertifType type)
  {
    PTEID_Certificate ret = new PTEID_Certificate(pteidlib_dotNetPINVOKE.PTEID_Certificates_getCert__SWIG_1(swigCPtr, (int)type), false);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Return the RRN certificate from the card.</summary>
  public PTEID_Certificate getRrn()
  {
    PTEID_Certificate ret = new PTEID_Certificate(pteidlib_dotNetPINVOKE.PTEID_Certificates_getRrn(swigCPtr), false);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Return the root certificate from the card.</summary>
  public PTEID_Certificate getRoot()
  {
    PTEID_Certificate ret = new PTEID_Certificate(pteidlib_dotNetPINVOKE.PTEID_Certificates_getRoot(swigCPtr), false);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Return the ca certificate from the card.</summary>
  public PTEID_Certificate getCA()
  {
    PTEID_Certificate ret = new PTEID_Certificate(pteidlib_dotNetPINVOKE.PTEID_Certificates_getCA(swigCPtr), false);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Return the signature certificate from the card.</summary>
  public PTEID_Certificate getSignature()
  {
    PTEID_Certificate ret = new PTEID_Certificate(pteidlib_dotNetPINVOKE.PTEID_Certificates_getSignature(swigCPtr), false);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Return the authentication certificate from the card.</summary>
  public PTEID_Certificate getAuthentication()
  {
    PTEID_Certificate ret = new PTEID_Certificate(pteidlib_dotNetPINVOKE.PTEID_Certificates_getAuthentication(swigCPtr), false);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Add a new certificate to the store.</summary>
  public PTEID_Certificate addCertificate(PTEID_ByteArray cert)
  {
    PTEID_Certificate ret = new PTEID_Certificate(pteidlib_dotNetPINVOKE.PTEID_Certificates_addCertificate(swigCPtr, PTEID_ByteArray.getCPtr(cert)), false);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

}

}
