Skip to content

Commit

Permalink
Implement IInfraction for Infraction class
Browse files Browse the repository at this point in the history
Also reverts from record to class because of custom equality requirement
  • Loading branch information
oliverbooth committed Mar 13, 2022
1 parent 90a08eb commit a71e7c2
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions Hammer/Data/Infraction.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
using System;
using System;
using System.Diagnostics.CodeAnalysis;
using Hammer.API;

namespace Hammer.Data;

/// <summary>
/// Represents an infraction.
/// </summary>
public record Infraction
internal class Infraction : IInfraction
{
/// <summary>
/// Gets or sets the time at which this infraction expires.
/// </summary>
/// <value>The expiration time.</value>
public DateTimeOffset? ExpirationTime { get; set; }

/// <summary>
/// Gets or sets the ID of the infraction.
/// </summary>
/// <value>The ID of the infraction.</value>
public int Id { get; set; }
public long Id { get; set; }

/// <summary>
/// Gets or sets the ID fo the guild in which this infraction was issued.
Expand All @@ -35,7 +43,7 @@ public record Infraction
/// Gets or sets the time of the infraction.
/// </summary>
/// <value>The time of the infraction.</value>
public DateTimeOffset Time { get; set; } = DateTimeOffset.UtcNow;
public DateTimeOffset IssuedAt { get; set; } = DateTimeOffset.UtcNow;

/// <summary>
/// Gets or sets the type of the infraction.
Expand All @@ -48,4 +56,35 @@ public record Infraction
/// </summary>
/// <value>The ID of the user who received this infraction.</value>
public ulong UserId { get; set; }

/// <inheritdoc />
public bool Equals(IInfraction? other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
if (other is not Infraction infraction) return false;
return Id == infraction.Id;
}

/// <inheritdoc />
public int CompareTo(IInfraction? other)
{
if (other is null) return 1;
return IssuedAt.CompareTo(other.IssuedAt);
}

/// <inheritdoc />
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj is IInfraction other && Equals(other);
}

/// <inheritdoc />
[SuppressMessage("ReSharper", "NonReadonlyMemberInGetHashCode")]
public override int GetHashCode()
{
return Id.GetHashCode();
}
}

0 comments on commit a71e7c2

Please sign in to comment.