|
| 1 | +namespace Cronofy |
| 2 | +{ |
| 3 | + using System; |
| 4 | + using System.Linq; |
| 5 | + |
| 6 | + /// <summary> |
| 7 | + /// Class for representing an availability rule. |
| 8 | + /// </summary> |
| 9 | + public sealed class AvailabilityRule |
| 10 | + { |
| 11 | + /// <summary> |
| 12 | + /// Gets or sets the unique identifier of the availability rule. |
| 13 | + /// </summary> |
| 14 | + /// <value> |
| 15 | + /// The unique identifier of the availability rule. |
| 16 | + /// </value> |
| 17 | + public string AvailabilityRuleId { get; set; } |
| 18 | + |
| 19 | + /// <summary> |
| 20 | + /// Gets or sets the time zone for which the availability rule start and end times are represented in. |
| 21 | + /// </summary> |
| 22 | + /// <value> |
| 23 | + /// The time zone for which the availability rule start and end times are represented in. |
| 24 | + /// </value> |
| 25 | + public string TimeZoneId { get; set; } |
| 26 | + |
| 27 | + /// <summary> |
| 28 | + /// Gets or sets the calendars that should impact the user's availability. |
| 29 | + /// </summary> |
| 30 | + /// <value> |
| 31 | + /// The calendars that should impact the user's availability. |
| 32 | + /// </value> |
| 33 | + public string[] CalendarIds { get; set; } |
| 34 | + |
| 35 | + /// <summary> |
| 36 | + /// Gets or sets the weekly recurring periods for the availability rule. |
| 37 | + /// </summary> |
| 38 | + /// <value> |
| 39 | + /// The weekly recurring periods for the availability rule. |
| 40 | + /// </value> |
| 41 | + public WeeklyPeriod[] WeeklyPeriods { get; set; } |
| 42 | + |
| 43 | + /// <inheritdoc /> |
| 44 | + public override int GetHashCode() |
| 45 | + { |
| 46 | + return this.AvailabilityRuleId.GetHashCode(); |
| 47 | + } |
| 48 | + |
| 49 | + /// <inheritdoc/> |
| 50 | + public override bool Equals(object obj) |
| 51 | + { |
| 52 | + if (ReferenceEquals(null, obj)) |
| 53 | + { |
| 54 | + return false; |
| 55 | + } |
| 56 | + |
| 57 | + if (ReferenceEquals(this, obj)) |
| 58 | + { |
| 59 | + return true; |
| 60 | + } |
| 61 | + |
| 62 | + return obj is AvailabilityRule && this.Equals((AvailabilityRule)obj); |
| 63 | + } |
| 64 | + |
| 65 | + /// <summary> |
| 66 | + /// Determines whether the specified <see cref="AvailabilityRule"/> |
| 67 | + /// is equal to the current <see cref="AvailabilityRule"/>. |
| 68 | + /// </summary> |
| 69 | + /// <param name="other"> |
| 70 | + /// The <see cref="AvailabilityRule"/> to compare with the current |
| 71 | + /// <see cref="AvailabilityRule"/>. |
| 72 | + /// </param> |
| 73 | + /// <returns> |
| 74 | + /// <c>true</c> if the specified <see cref="AvailabilityRule"/> is |
| 75 | + /// equal to the current <see cref="AvailabilityRule"/>; otherwise, |
| 76 | + /// <c>false</c>. |
| 77 | + /// </returns> |
| 78 | + public bool Equals(AvailabilityRule other) |
| 79 | + { |
| 80 | + return this.AvailabilityRuleId == other.AvailabilityRuleId && |
| 81 | + this.TimeZoneId == other.TimeZoneId && |
| 82 | + ((this.CalendarIds == null && other.CalendarIds == null) || (this.CalendarIds != null && other.CalendarIds != null && this.CalendarIds.SequenceEqual(other.CalendarIds))) && |
| 83 | + this.WeeklyPeriods.SequenceEqual(other.WeeklyPeriods); |
| 84 | + } |
| 85 | + |
| 86 | + /// <inheritdoc/> |
| 87 | + public override string ToString() |
| 88 | + { |
| 89 | + return string.Format( |
| 90 | + "<{0} AvailabilityRuleId={1}, TimeZoneId={2}, CalendarIds={3}, WeeklyPeriods=[{4}]>", |
| 91 | + this.GetType(), |
| 92 | + this.AvailabilityRuleId, |
| 93 | + this.TimeZoneId, |
| 94 | + this.CalendarIds == null ? "null" : string.Format("[{0}]", string.Join(", ", this.CalendarIds)), |
| 95 | + string.Join(", ", this.WeeklyPeriods.Select(weeklyPeriod => weeklyPeriod.ToString()))); |
| 96 | + } |
| 97 | + |
| 98 | + /// <summary> |
| 99 | + /// Class to represent a weekly period. |
| 100 | + /// </summary> |
| 101 | + public class WeeklyPeriod |
| 102 | + { |
| 103 | + /// <summary> |
| 104 | + /// Gets or sets the week day the period applies to. |
| 105 | + /// </summary> |
| 106 | + /// <value> |
| 107 | + /// The week day the period applies to. |
| 108 | + /// </value> |
| 109 | + public DayOfWeek Day { get; set; } |
| 110 | + |
| 111 | + /// <summary> |
| 112 | + /// Gets or sets the time of day the period should start. |
| 113 | + /// </summary> |
| 114 | + /// <value> |
| 115 | + /// The time of day the period should start. |
| 116 | + /// </value> |
| 117 | + public string StartTime { get; set; } |
| 118 | + |
| 119 | + /// <summary> |
| 120 | + /// Gets or sets the time of day the period should end. |
| 121 | + /// </summary> |
| 122 | + /// <value> |
| 123 | + /// The time of day the period should end. |
| 124 | + /// </value> |
| 125 | + public string EndTime { get; set; } |
| 126 | + |
| 127 | + /// <inheritdoc /> |
| 128 | + public override int GetHashCode() |
| 129 | + { |
| 130 | + return this.Day.GetHashCode() ^ this.StartTime.GetHashCode() ^ this.EndTime.GetHashCode(); |
| 131 | + } |
| 132 | + |
| 133 | + /// <inheritdoc/> |
| 134 | + public override bool Equals(object obj) |
| 135 | + { |
| 136 | + if (ReferenceEquals(null, obj)) |
| 137 | + { |
| 138 | + return false; |
| 139 | + } |
| 140 | + |
| 141 | + if (ReferenceEquals(this, obj)) |
| 142 | + { |
| 143 | + return true; |
| 144 | + } |
| 145 | + |
| 146 | + return obj is WeeklyPeriod && this.Equals((WeeklyPeriod)obj); |
| 147 | + } |
| 148 | + |
| 149 | + /// <summary> |
| 150 | + /// Determines whether the specified <see cref="WeeklyPeriod"/> |
| 151 | + /// is equal to the current <see cref="WeeklyPeriod"/>. |
| 152 | + /// </summary> |
| 153 | + /// <param name="other"> |
| 154 | + /// The <see cref="WeeklyPeriod"/> to compare with the current |
| 155 | + /// <see cref="WeeklyPeriod"/>. |
| 156 | + /// </param> |
| 157 | + /// <returns> |
| 158 | + /// <c>true</c> if the specified <see cref="WeeklyPeriod"/> is |
| 159 | + /// equal to the current <see cref="WeeklyPeriod"/>; otherwise, |
| 160 | + /// <c>false</c>. |
| 161 | + /// </returns> |
| 162 | + public bool Equals(WeeklyPeriod other) |
| 163 | + { |
| 164 | + return this.Day == other.Day && |
| 165 | + this.StartTime == other.StartTime && |
| 166 | + this.EndTime == other.EndTime; |
| 167 | + } |
| 168 | + |
| 169 | + /// <inheritdoc/> |
| 170 | + public override string ToString() |
| 171 | + { |
| 172 | + return string.Format( |
| 173 | + "<{0} Day={1}, StartTime={2}, EndTime={3}>", |
| 174 | + this.GetType(), |
| 175 | + this.Day, |
| 176 | + this.StartTime, |
| 177 | + this.EndTime); |
| 178 | + } |
| 179 | + } |
| 180 | + } |
| 181 | +} |
0 commit comments