//
// Вот этим сайтом https://app.quicktype.io/?l=csharp
// Не является точной копией ответа, могут быть отличия
#nullable enable
#pragma warning disable CS8618
#pragma warning disable CS8601
#pragma warning disable CS8603
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Globalization;
namespace SfeduSchedule;
public partial class Schedule
{
[JsonPropertyName("_embedded")] public Embedded Embedded { get; set; }
[JsonPropertyName("page")] public Page Page { get; set; }
}
public partial class Embedded
{
[JsonPropertyName("events")] public Event[] Events { get; set; }
[JsonPropertyName("course-unit-realizations")]
public CourseUnitRealization[] CourseUnitRealizations { get; set; }
[JsonPropertyName("cycle-realizations")]
public CycleRealization[] CycleRealizations { get; set; }
[JsonPropertyName("lesson-realization-teams")]
public LessonRealizationTeam[] LessonRealizationTeams { get; set; }
[JsonPropertyName("lesson-realizations")]
public LessonRealization[] LessonRealizations { get; set; }
[JsonPropertyName("event-locations")] public EventLocation[] EventLocations { get; set; }
[JsonPropertyName("durations")] public Duration[] Durations { get; set; }
[JsonPropertyName("event-rooms")] public EventRoom[] EventRooms { get; set; }
[JsonPropertyName("rooms")] public Room[] Rooms { get; set; }
[JsonPropertyName("buildings")] public BuildingElement[] Buildings { get; set; }
[JsonPropertyName("event-teams")] public EventTeam[] EventTeams { get; set; }
[JsonPropertyName("event-organizers")] public EventOrganizer[] EventOrganizers { get; set; }
[JsonPropertyName("event-attendees")] public EventAttendee[] EventAttendees { get; set; }
[JsonPropertyName("persons")] public Person[] Persons { get; set; }
}
public partial class BuildingElement
{
[JsonPropertyName("name")] public string Name { get; set; }
[JsonPropertyName("nameShort")] public string NameShort { get; set; }
[JsonPropertyName("address")] public string Address { get; set; }
[JsonPropertyName("searchableAddress")]
public string SearchableAddress { get; set; }
[JsonPropertyName("displayOrder")] public long DisplayOrder { get; set; }
[JsonPropertyName("_links")] public BuildingLinks Links { get; set; }
[JsonPropertyName("id")] public Guid Id { get; set; }
}
public partial class BuildingLinks
{
[JsonPropertyName("self")] public Self Self { get; set; }
}
public partial class Self
{
[JsonPropertyName("href")] public string Href { get; set; }
}
public partial class CourseUnitRealization
{
[JsonPropertyName("name")] public string Name { get; set; }
[JsonPropertyName("nameShort")] public string NameShort { get; set; }
[JsonPropertyName("prototypeId")] public Guid PrototypeId { get; set; }
[JsonPropertyName("_links")] public CourseUnitRealizationLinks Links { get; set; }
[JsonPropertyName("id")] public Guid Id { get; set; }
}
public partial class CourseUnitRealizationLinks
{
[JsonPropertyName("self")] public Self Self { get; set; }
[JsonPropertyName("planning-period")] public Self PlanningPeriod { get; set; }
}
public partial class CycleRealization
{
[JsonPropertyName("name")] public string Name { get; set; }
[JsonPropertyName("nameShort")] public string NameShort { get; set; }
[JsonPropertyName("code")] public string Code { get; set; }
[JsonPropertyName("courseUnitRealizationNameShort")]
public string CourseUnitRealizationNameShort { get; set; }
[JsonPropertyName("_links")] public CycleRealizationLinks Links { get; set; }
[JsonPropertyName("id")] public Guid Id { get; set; }
}
public partial class CycleRealizationLinks
{
[JsonPropertyName("self")] public Self Self { get; set; }
[JsonPropertyName("course-unit-realization")]
public Self CourseUnitRealization { get; set; }
}
public partial class Duration
{
[JsonPropertyName("eventId")] public Guid EventId { get; set; }
[JsonPropertyName("value")] public long Value { get; set; }
[JsonPropertyName("timeUnitId")] public string TimeUnitId { get; set; }
[JsonPropertyName("minutes")] public long Minutes { get; set; }
[JsonPropertyName("_links")] public DurationLinks Links { get; set; }
}
public partial class DurationLinks
{
[JsonPropertyName("self")] public Self[] Self { get; set; }
[JsonPropertyName("time-unit")] public Self TimeUnit { get; set; }
}
public partial class EventAttendee
{
[JsonPropertyName("roleId")] public string RoleId { get; set; }
[JsonPropertyName("roleName")] public string RoleName { get; set; }
[JsonPropertyName("roleNamePlural")] public string RoleNamePlural { get; set; }
[JsonPropertyName("roleDisplayOrder")] public long RoleDisplayOrder { get; set; }
[JsonPropertyName("_links")] public EventAttendeeLinks Links { get; set; }
[JsonPropertyName("id")] public Guid Id { get; set; }
}
public partial class EventAttendeeLinks
{
[JsonPropertyName("self")] public Self Self { get; set; }
[JsonPropertyName("event")] public Self Event { get; set; }
[JsonPropertyName("person")] public Self Person { get; set; }
}
public partial class EventLocation
{
[JsonPropertyName("eventId")] public Guid EventId { get; set; }
[JsonPropertyName("customLocation")] public string CustomLocation { get; set; }
[JsonPropertyName("_links")] public EventLocationLinks Links { get; set; }
}
public partial class EventLocationLinks
{
[JsonPropertyName("self")] public Self[] Self { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("event-rooms")]
public Self EventRooms { get; set; }
}
public partial class EventOrganizer
{
[JsonPropertyName("eventId")] public Guid EventId { get; set; }
[JsonPropertyName("_links")] public EventOrganizerLinks Links { get; set; }
}
public partial class EventOrganizerLinks
{
[JsonPropertyName("self")] public Self Self { get; set; }
[JsonPropertyName("event")] public Self Event { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("event-attendees")]
public EventAttendees? EventAttendees { get; set; }
}
public partial class EventRoom
{
[JsonPropertyName("_links")] public EventRoomLinks Links { get; set; }
[JsonPropertyName("id")] public Guid Id { get; set; }
}
public partial class EventRoomLinks
{
[JsonPropertyName("self")] public Self Self { get; set; }
[JsonPropertyName("event")] public Self Event { get; set; }
[JsonPropertyName("room")] public Self Room { get; set; }
}
public partial class EventTeam
{
[JsonPropertyName("eventId")] public Guid EventId { get; set; }
[JsonPropertyName("size")] public long Size { get; set; }
[JsonPropertyName("_links")] public EventTeamLinks Links { get; set; }
}
public partial class EventTeamLinks
{
[JsonPropertyName("self")] public Self Self { get; set; }
[JsonPropertyName("event")] public Self Event { get; set; }
}
public partial class Event
{
[JsonPropertyName("name")] public string Name { get; set; }
[JsonPropertyName("nameShort")] public string NameShort { get; set; }
[JsonPropertyName("description")] public object Description { get; set; }
[JsonPropertyName("typeId")] public string TypeId { get; set; }
[JsonPropertyName("formatId")] public string FormatId { get; set; }
[JsonPropertyName("start")] public DateTime Start { get; set; }
[JsonPropertyName("end")] public DateTime End { get; set; }
[JsonPropertyName("startsAtLocal")] public DateTime StartsAtLocal { get; set; }
[JsonPropertyName("endsAtLocal")] public DateTime EndsAtLocal { get; set; }
[JsonPropertyName("startsAt")] public DateTime StartsAt { get; set; }
[JsonPropertyName("endsAt")] public DateTime EndsAt { get; set; }
[JsonPropertyName("holdingStatus")] public HoldingStatus HoldingStatus { get; set; }
[JsonPropertyName("repeatedLessonRealization")]
public RepeatedLessonRealization RepeatedLessonRealization { get; set; }
[JsonPropertyName("userRoleIds")] public string[] UserRoleIds { get; set; }
[JsonPropertyName("lessonTemplateId")] public Guid? LessonTemplateId { get; set; }
[JsonPropertyName("__version")] public long Version { get; set; }
[JsonPropertyName("_links")] public Dictionary Links { get; set; }
[JsonPropertyName("id")] public Guid Id { get; set; }
}
public partial class HoldingStatus
{
[JsonPropertyName("id")] public string Id { get; set; }
[JsonPropertyName("name")] public string Name { get; set; }
[JsonPropertyName("audModifiedAt")] public DateTimeOffset? AudModifiedAt { get; set; }
[JsonPropertyName("audModifiedBy")] public Guid? AudModifiedBy { get; set; }
[JsonPropertyName("audModifiedBySystem")]
public bool? AudModifiedBySystem { get; set; }
}
public partial class RepeatedLessonRealization
{
[JsonPropertyName("name")] public string Name { get; set; }
[JsonPropertyName("lessonTeamName")] public string LessonTeamName { get; set; }
}
public partial class LessonRealizationTeam
{
[JsonPropertyName("name")] public string Name { get; set; }
[JsonPropertyName("cycleRealizationId")]
public Guid CycleRealizationId { get; set; }
[JsonPropertyName("_links")] public BuildingLinks Links { get; set; }
[JsonPropertyName("id")] public Guid Id { get; set; }
}
public partial class LessonRealization
{
[JsonPropertyName("name")] public string Name { get; set; }
[JsonPropertyName("nameShort")] public string NameShort { get; set; }
[JsonPropertyName("prototypeId")] public Guid PrototypeId { get; set; }
[JsonPropertyName("ordinal")] public long Ordinal { get; set; }
[JsonPropertyName("_links")] public BuildingLinks Links { get; set; }
[JsonPropertyName("id")] public Guid Id { get; set; }
}
public partial class Person
{
[JsonPropertyName("lastName")] public string LastName { get; set; }
[JsonPropertyName("firstName")] public string FirstName { get; set; }
[JsonPropertyName("middleName")] public string MiddleName { get; set; }
[JsonPropertyName("fullName")] public string FullName { get; set; }
[JsonPropertyName("_links")] public BuildingLinks Links { get; set; }
[JsonPropertyName("id")] public Guid Id { get; set; }
}
public partial class Room
{
[JsonPropertyName("name")] public string Name { get; set; }
[JsonPropertyName("nameShort")] public string NameShort { get; set; }
[JsonPropertyName("building")] public RoomBuilding Building { get; set; }
[JsonPropertyName("projectorAvailable")]
public bool ProjectorAvailable { get; set; }
[JsonPropertyName("totalCapacity")] public long TotalCapacity { get; set; }
[JsonPropertyName("workingCapacity")] public long WorkingCapacity { get; set; }
[JsonPropertyName("deletedAtUtc")] public object DeletedAtUtc { get; set; }
[JsonPropertyName("_links")] public RoomLinks Links { get; set; }
[JsonPropertyName("id")] public Guid Id { get; set; }
}
public partial class RoomBuilding
{
[JsonPropertyName("id")] public Guid Id { get; set; }
[JsonPropertyName("name")] public string Name { get; set; }
[JsonPropertyName("nameShort")] public string NameShort { get; set; }
[JsonPropertyName("address")] public string Address { get; set; }
[JsonPropertyName("displayOrder")] public long DisplayOrder { get; set; }
}
public partial class RoomLinks
{
[JsonPropertyName("self")] public Self Self { get; set; }
[JsonPropertyName("type")] public Self Type { get; set; }
[JsonPropertyName("building")] public Self Building { get; set; }
}
public partial class Page
{
[JsonPropertyName("size")] public long Size { get; set; }
[JsonPropertyName("totalElements")] public long TotalElements { get; set; }
[JsonPropertyName("totalPages")] public long TotalPages { get; set; }
[JsonPropertyName("number")] public long Number { get; set; }
}
public partial struct EventAttendees
{
public Self Self;
public Self[] SelfArray;
public static implicit operator EventAttendees(Self Self) => new EventAttendees { Self = Self };
public static implicit operator EventAttendees(Self[] SelfArray) => new EventAttendees { SelfArray = SelfArray };
}
public partial class Schedule
{
public static Schedule FromJson(string json) =>
JsonSerializer.Deserialize(json, SfeduSchedule.Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this Schedule self) => JsonSerializer.Serialize(self, SfeduSchedule.Converter.Settings);
}
internal static class Converter
{
public static readonly JsonSerializerOptions Settings = new(JsonSerializerDefaults.General)
{
Converters =
{
EventAttendeesConverter.Singleton,
new DateOnlyConverter(),
new TimeOnlyConverter(),
IsoDateTimeOffsetConverter.Singleton
},
};
}
internal class EventAttendeesConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(EventAttendees);
public override EventAttendees Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
switch (reader.TokenType)
{
case JsonTokenType.StartObject:
var objectValue = JsonSerializer.Deserialize(ref reader, options);
return new EventAttendees { Self = objectValue };
case JsonTokenType.StartArray:
var arrayValue = JsonSerializer.Deserialize(ref reader, options);
return new EventAttendees { SelfArray = arrayValue };
}
throw new Exception("Cannot unmarshal type EventAttendees");
}
public override void Write(Utf8JsonWriter writer, EventAttendees value, JsonSerializerOptions options)
{
if (value.SelfArray != null)
{
JsonSerializer.Serialize(writer, value.SelfArray, options);
return;
}
if (value.Self != null)
{
JsonSerializer.Serialize(writer, value.Self, options);
return;
}
throw new Exception("Cannot marshal type EventAttendees");
}
public static readonly EventAttendeesConverter Singleton = new EventAttendeesConverter();
}
public class DateOnlyConverter : JsonConverter
{
private readonly string serializationFormat;
public DateOnlyConverter() : this(null)
{
}
public DateOnlyConverter(string? serializationFormat)
{
this.serializationFormat = serializationFormat ?? "yyyy-MM-dd";
}
public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var value = reader.GetString();
return DateOnly.Parse(value!);
}
public override void Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options)
=> writer.WriteStringValue(value.ToString(serializationFormat));
}
public class TimeOnlyConverter : JsonConverter
{
private readonly string serializationFormat;
public TimeOnlyConverter() : this(null)
{
}
public TimeOnlyConverter(string? serializationFormat)
{
this.serializationFormat = serializationFormat ?? "HH:mm:ss.fff";
}
public override TimeOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var value = reader.GetString();
return TimeOnly.Parse(value!);
}
public override void Write(Utf8JsonWriter writer, TimeOnly value, JsonSerializerOptions options)
=> writer.WriteStringValue(value.ToString(serializationFormat));
}
internal class IsoDateTimeOffsetConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(DateTimeOffset);
private const string DefaultDateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK";
private DateTimeStyles _dateTimeStyles = DateTimeStyles.RoundtripKind;
private string? _dateTimeFormat;
private CultureInfo? _culture;
public DateTimeStyles DateTimeStyles
{
get => _dateTimeStyles;
set => _dateTimeStyles = value;
}
public string? DateTimeFormat
{
get => _dateTimeFormat ?? string.Empty;
set => _dateTimeFormat = (string.IsNullOrEmpty(value)) ? null : value;
}
public CultureInfo Culture
{
get => _culture ?? CultureInfo.CurrentCulture;
set => _culture = value;
}
public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options)
{
string text;
if ((_dateTimeStyles & DateTimeStyles.AdjustToUniversal) == DateTimeStyles.AdjustToUniversal
|| (_dateTimeStyles & DateTimeStyles.AssumeUniversal) == DateTimeStyles.AssumeUniversal)
{
value = value.ToUniversalTime();
}
text = value.ToString(_dateTimeFormat ?? DefaultDateTimeFormat, Culture);
writer.WriteStringValue(text);
}
public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
string? dateText = reader.GetString();
if (string.IsNullOrEmpty(dateText) == false)
{
if (!string.IsNullOrEmpty(_dateTimeFormat))
{
return DateTimeOffset.ParseExact(dateText, _dateTimeFormat, Culture, _dateTimeStyles);
}
else
{
return DateTimeOffset.Parse(dateText, Culture, _dateTimeStyles);
}
}
else
{
return default(DateTimeOffset);
}
}
public static readonly IsoDateTimeOffsetConverter Singleton = new IsoDateTimeOffsetConverter();
}
#pragma warning restore CS8618
#pragma warning restore CS8601
#pragma warning restore CS8603