using System; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Windows.Media; using System.Windows.Media.Imaging; using Comal.Classes; using InABox.WPF; using PropertyChanged; using Syncfusion.UI.Xaml.Scheduler; namespace PRSDesktop { public interface ICalendarAppointment { // object Id { get; } Brush Background { get; } Brush BorderBrush { get; } Brush Foreground { get; } string? Subject { get; } string? Notes { get; } // ObservableCollection ResourceIdCollection { get; } // DateTime StartTime { get; } // DateTime EndTime { get; } BitmapImage? Image { get; } object Model { get; } Employee? Employee { get; } TimeSpan StartTime { get; } TimeSpan EndTime { get; } DateTime Date { get; } bool CanAdjust { get; } } public interface ICalendarAppointment : ICalendarAppointment where T : notnull { new T Model { get; } object ICalendarAppointment.Model => Model; } [DoNotNotify] public abstract class CalendarAppointment : ICalendarAppointment, INotifyPropertyChanged where T : notnull { private Employee? _employee; // Nullable because this assignment might be rendered on a column that doesn't exist. public virtual Employee? Employee { get => _employee; set { _employee = value; OnPropertyChanged(); } } public BitmapImage? Image { get; set; } public string? Subject { get; set; } public string? Notes { get; set; } public T Model { get; } private Brush _background; public Brush Background { get => _background; [MemberNotNull(nameof(_background), nameof(BorderBrush))] private set { _background = value; if(value is SolidColorBrush brush) { BorderBrush = brush.Color.AdjustBrightness(-0.5f).ToBrush(); } else { BorderBrush = Colors.Black.ToBrush(); } } } public Brush BorderBrush { get; private set; } public Brush Foreground { get; private set; } public abstract TimeSpan StartTime { get; set; } public abstract TimeSpan EndTime { get; set; } public abstract DateTime Date { get; set; } public abstract bool CanAdjust { get; } private Func Colour; public CalendarAppointment(T model, Employee employee, Func color) { Model = model; _employee = employee; Colour = color; UpdateColour(); } [MemberNotNull(nameof(_background), nameof(Foreground), nameof(BorderBrush))] protected void UpdateColour() { var c = Colour(Model); Color c2 = string.IsNullOrWhiteSpace(c) ? Colors.White : (Color)ColorConverter.ConvertFromString(c); Background = new SolidColorBrush(c2); Foreground = new SolidColorBrush(ImageUtils.GetForegroundColor(c2)); } public event PropertyChangedEventHandler? PropertyChanged; protected void OnPropertyChanged([CallerMemberName] string? propertyName = null) { PropertyChanged?.Invoke(this, new(propertyName)); } } public class CalendarAppointments : ScheduleAppointmentCollection //ObservableCollection { }} { } }