using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Security;
using System.Net.WebSockets;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1.WebSocketClient
{
    internal static class WebSocketClientTest
    {
        public static async Task Test()
        {
            var url = new Uri("wss://localhost/PHSimulator006501");
            var clientCertificate = X509Certificate2.CreateFromPemFile("crt.cert.pem", "key.key.pem");
            var tmpCert = new X509Certificate2(clientCertificate.Export(X509ContentType.Pfx));
            //var clientCertificate = new X509Certificate2("PHSimulator006501.pfx", "test");
            //var clienCertificateRoot = X509Certificate2.CreateFromPemFile("rca.crt");
            var client = new ClientWebSocket();
            client.Options.AddSubProtocol("ocpp1.6");
            client.Options.ClientCertificates.Add(tmpCert);
            client.Options.RemoteCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateRemoteCertificate);
            //client.Options.ClientCertificates.Add(clienCertificateRoot);
            await client.ConnectAsync(url, default);
        }

        private static bool ValidateRemoteCertificate(object sender, X509Certificate? certificate, X509Chain? chain, SslPolicyErrors sslPolicyErrors)
        {
            return true;
        }
    }
}