﻿using BookReviews.Domain.MembershipRebootCustomizationObjects;
using BrockAllen.MembershipReboot;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BookReviews.Domain
{
    //public class UserCertificateAdapter
    //{
    //    private UserCertificateCustomized userCertificateCustomized = null;

    //    public UserCertificateAdapter()
    //    {
    //        userCertificateCustomized = new UserCertificateCustomized();
    //    }

    //    public UserCertificateAdapter(UserCertificate userCertificate)
    //    {
    //        userCertificateCustomized = (UserCertificateCustomized)userCertificate;
    //    }

    //    //public virtual UserCertificateAdapterPK Id { get; protected internal set; }

    //    public virtual string Thumbprint { get { return userCertificateCustomized.Thumbprint; } protected internal set { userCertificateCustomized.Thumbprint = value; } }
    //    public virtual Guid UserAccountID { get { return userCertificateCustomized.UserAccountID; } protected internal set { userCertificateCustomized.UserAccountID = value; } }
    //    public virtual string Subject { get { return userCertificateCustomized.Subject; } protected internal set { userCertificateCustomized.Subject = value; } }
    //    public virtual UserAccountAdapter User { get { return new UserAccountAdapter(userCertificateCustomized.User); } protected internal set { userCertificateCustomized.User = new UserAccountCustomized(value); } }

    //    public override bool Equals(object obj)
    //    {
    //        // as zwraca typowany obiekt albo null jezeli nie moze dokonac poprawnego rzutowania
    //        // dlatego nie trzeba sprawdzac obj == null
    //        UserCertificateAdapter typedObj = obj as UserCertificateAdapter;

    //        if (typedObj == null)
    //        {
    //            return false;
    //        }

    //        if (UserAccountID == typedObj.UserAccountID
    //            && Thumbprint == typedObj.Thumbprint)
    //        {
    //            return true;
    //        }

    //        return false;
    //    }

    //    public override int GetHashCode()
    //    {
    //        return (UserAccountID + "|" + Thumbprint).GetHashCode();
    //    }
    //}

    public class UserCertificateAdapter : UserCertificate
    {
        public UserCertificateAdapter()
        {
        }

        public UserCertificateAdapter(UserCertificate userCertificate)
        {
            Subject = userCertificate.Subject;
            Thumbprint = userCertificate.Thumbprint;
            //User = new UserAccountAdapter(userCertificate.User);
            UserAccountID = userCertificate.UserAccountID;
        }

        ////public virtual UserCertificateAdapterPK Id { get; protected internal set; }

        //public virtual new string Thumbprint { get; protected internal set; }
        //public virtual new Guid UserAccountID { get; protected internal set; }
        //public virtual new string Subject { get; protected internal set; }
        public virtual new UserAccountAdapter User { get { return new UserAccountAdapter(base.User); } protected internal set { base.User = value; } }

        public override bool Equals(object obj)
        {
            // as zwraca typowany obiekt albo null jezeli nie moze dokonac poprawnego rzutowania
            // dlatego nie trzeba sprawdzac obj == null
            UserCertificateAdapter typedObj = obj as UserCertificateAdapter;

            if (typedObj == null)
            {
                return false;
            }

            if (UserAccountID == typedObj.UserAccountID
                && Thumbprint == typedObj.Thumbprint)
            {
                return true;
            }

            return false;
        }

        public override int GetHashCode()
        {
            return (UserAccountID + "|" + Thumbprint).GetHashCode();
        }
    }
}
