using System;
using System.Collections.Generic;

namespace skyscraper5.Skyscraper.Scraper.Storage.Utilities
{
    public class DatabaseKeyT2MiTransmitter : IEquatable<DatabaseKeyT2MiTransmitter>
    {
        private readonly int currentNetworkId;
        private readonly int currentTransportStreamId;
        private readonly int relatedPid;
        private readonly ushort txIdentifier;

        public DatabaseKeyT2MiTransmitter(int currentNetworkId, int currentTransportStreamId, int relatedPid, ushort txIdentifier)
        {
            this.currentNetworkId = currentNetworkId;
            this.currentTransportStreamId = currentTransportStreamId;
            this.relatedPid = relatedPid;
            this.txIdentifier = txIdentifier;
        }

        public override bool Equals(object obj)
        {
            return Equals(obj as DatabaseKeyT2MiTransmitter);
        }

        public bool Equals(DatabaseKeyT2MiTransmitter other)
        {
            return other is not null &&
                   currentNetworkId == other.currentNetworkId &&
                   currentTransportStreamId == other.currentTransportStreamId &&
                   relatedPid == other.relatedPid &&
                   txIdentifier == other.txIdentifier;
        }

        public override int GetHashCode()
        {
            return HashCode.Combine(currentNetworkId, currentTransportStreamId, relatedPid, txIdentifier);
        }

        public static bool operator ==(DatabaseKeyT2MiTransmitter left, DatabaseKeyT2MiTransmitter right)
        {
            return EqualityComparer<DatabaseKeyT2MiTransmitter>.Default.Equals(left, right);
        }

        public static bool operator !=(DatabaseKeyT2MiTransmitter left, DatabaseKeyT2MiTransmitter right)
        {
            return !(left == right);
        }
    }
}
