using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Valg.EVA.Skanning.Services.Security;

namespace Valg.EVA.Skanning.Scan.Startup.StateReporting
{
    public class StateReport
    {
        protected IReportSink ReportSink;

        public SecurityComplianceResult SecurityComplianceResult { get; set; }
        public string ScannerModel { get; set; }

        public StateReport()
        {

        }
        public static StateReport Create(string scannerModel, IReportSink reportSink)
        {
            return new StateReport()
            {
                ScannerModel = scannerModel,
                ReportSink = reportSink
            };
        }

        public void GenerateAndSend()
        {
            var scanService = new Valg.EVA.Skanning.Services.Security.SecurityComplianceScanService();
            scanService.SecurityComplianceScanDone += result =>
            {
                SecurityComplianceResult = result;
                Send();
            };
            scanService.Scan();
        }

        private void Send()
        {
            ReportSink.Send(this);
        }

        public override bool Equals(object obj)
        {
            if (obj is StateReport other)
            {
                return Equals(other);
            }
            else
            {
                return base.Equals(obj);
            }
        }

        protected bool Equals(StateReport other)
        {
            return SecurityComplianceResult.Equals(other.SecurityComplianceResult) && string.Equals(ScannerModel, other.ScannerModel);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                var hashCode = SecurityComplianceResult.GetHashCode();
                hashCode = (hashCode * 397) ^ (ReportSink != null ? ReportSink.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (ScannerModel != null ? ScannerModel.GetHashCode() : 0);
                return hashCode;
            }
        }
    }
}

