using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
namespace gehGassiApp.Domain.Base
{
///
/// Basisklasse für eine Entität welche über Synchronisierungs-Eigenschaften verfügt
///
public class SyncEntity : ObservableObject, ISyncEntity
{
///
/// Guid als String - wird als Key verwendet.
/// Hier so gelöst, da nicht alle Datenbanken über Guids verfügen
///
[Key]
[MaxLength(128)]
[JsonPropertyName("id")]
public string Id { get; set; }
///
/// Eindeutiger Versions-Identifikator für diese Entität. Muss bei jeder Schreib-Operation gesetzt werden
///
[Timestamp]
[JsonPropertyName("version")]
public byte[] Version { get; set; }
///
/// Datum und Uhrzeit inkl. Zeitzone wann die letzte Aktualisierung stattgefunden hat.
///
[JsonPropertyName("updatedAt")]
public DateTimeOffset UpdatedAt { get; set; } = DateTimeOffset.UtcNow;
///
/// Gibt an ob diese Entität gelöscht wurde
///
[JsonPropertyName("deleted")]
public bool Deleted { get; set; }
/// Indicates whether the current object is equal to another object of the same type.
/// An object to compare with this object.
///
/// if the current object is equal to the parameter; otherwise, .
public bool Equals(ISyncEntity other)
=> other != null
&& Id == other.Id
&& UpdatedAt == other.UpdatedAt
&& Deleted == other.Deleted
&& Version.SequenceEqual(other.Version);
}
///
/// Basisklasse für eine Entität welche über Synchronisierungs-Eigenschaften verfügt für Views
///
public class SyncEntityVw : ObservableObject, ISyncEntity
{
///
/// Guid als String - wird als Key verwendet.
/// Hier so gelöst, da nicht alle Datenbanken über Guids verfügen
///
public string Id { get; set; }
///
/// Eindeutiger Versions-Identifikator für diese Entität. Muss bei jeder Schreib-Operation gesetzt werden
///
public byte[] Version { get; set; }
///
/// Datum und Uhrzeit inkl. Zeitzone wann die letzte Aktualisierung stattgefunden hat.
///
public DateTimeOffset UpdatedAt { get; set; } = DateTimeOffset.UtcNow;
///
/// Gibt an ob diese Entität gelöscht wurde
///
public bool Deleted { get; set; }
/// Indicates whether the current object is equal to another object of the same type.
/// An object to compare with this object.
///
/// if the current object is equal to the parameter; otherwise, .
public bool Equals(ISyncEntity other)
=> other != null
&& Id == other.Id
&& UpdatedAt == other.UpdatedAt
&& Deleted == other.Deleted
&& Version.SequenceEqual(other.Version);
}
}