using System.Text.Json;
using Beam.Abstractions;

namespace Beam.Models {
    public record class ArticleData : IArticleData {
        public string? Name { get; set; }
        public string[] Authors { get; set; } = [];
        public string? Language { get; set; }
        public string[] Categories { get; set; } = [];
        public string? Version { get; set; }
        public string? Description { get; set; }

        public string AsJson(JsonSerializerOptions? options = null) {
            return JsonSerializer.Serialize(this, options);
        }

        public virtual bool Equals(ArticleData? other) {
            if (other is null) return false;
            if (ReferenceEquals(this, other)) return true;
            return Name == other.Name && Authors.Equals(other.Authors) && Language == other.Language && Categories.Equals(other.Categories) && Version == other.Version && Description == other.Description;
        }

        public virtual bool Equals(IArticleData? other) {
            if (other is null) return false;
            if (ReferenceEquals(this, other)) return true;
            return Name == other.Name && Authors.Equals(other.Authors) && Language == other.Language && Categories.Equals(other.Categories) && Version == other.Version && Description == other.Description;
        }

        public override int GetHashCode() {
            unchecked {
                var hashCode = (Name != null ? Name.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ Authors.GetHashCode();
                hashCode = (hashCode * 397) ^ (Language != null ? Language.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ Categories.GetHashCode();
                hashCode = (hashCode * 397) ^ (Version != null ? Version.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (Description != null ? Description.GetHashCode() : 0);
                return hashCode;
            }
        }
    }
}
