use std::marker::PhantomData;

use ecdsa::PrimeCurve;
use elliptic_curve::PrimeCurveArithmetic;
use rustls::pki_types::{
    alg_id, AlgorithmIdentifier, InvalidSignature, SignatureVerificationAlgorithm,
};

#[derive(Debug)]
struct EcdsaVerify<C: PrimeCurve + PrimeCurveArithmetic>(PhantomData<C>);

pub(crate) static ECDSA_NISTP256_SHA256: &dyn SignatureVerificationAlgorithm =
    &EcdsaVerify::<p256::NistP256>(PhantomData);
pub(crate) static ECDSA_NISTP384_SHA384: &dyn SignatureVerificationAlgorithm =
    &EcdsaVerify::<p384::NistP384>(PhantomData);

impl<C: PrimeCurve + PrimeCurveArithmetic> SignatureVerificationAlgorithm for EcdsaVerify<C> {
    fn public_key_alg_id(&self) -> AlgorithmIdentifier {
        alg_id::ECDSA_P384
    }

    fn signature_alg_id(&self) -> AlgorithmIdentifier {
        alg_id::ECDSA_SHA384
    }

    fn verify_signature(
        &self,
        public_key: &[u8],
        message: &[u8],
        signature: &[u8],
    ) -> Result<(), InvalidSignature> {
        let _ = (public_key, message, signature);
        todo!("Implement signature verification for ECDSA, curves NISTP256, NISTP384")
    }
}
