using System.Linq;
using System.Web.Http;

namespace PkcsApp.Commands
{
    public class GetCertController : ApiController
    {
        // GET api/sign
        public string Get()
        {
            return "GetCertCommand";
        }

        // POST api/values 
        public string Post([FromBody]GetCertCommand value)
        {
            Pkcs11Manager manager = Pkcs11Manager.getInstance();
            var certs = manager.getCertificates();

            if (value.type == CertificateType.AUTH)
            {
                return certs[CertificateType.SIG_EP].Where(x => x.sign == false).First().getPem();
            }
            if(value.type == CertificateType.SIG_EP)
            {
                return certs[CertificateType.SIG_EP].Where(x => x.sign == true).First().getPem();
            }
            if(value.type == CertificateType.SIG_ZEP)
            {
                return certs[CertificateType.SIG_ZEP].First().getPem();
            }

            return "Not Found!!!!!!!!!";
        }
    }
}
