// Copyright (c) 2023 schick Informatik // Description: Container model for shipcall related info // using BreCalClient.misc.Client; using BreCalClient.misc.Model; using System; using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; namespace BreCalClient { /// /// Container model to aggregate separate models for the Shipcall control data binding /// public class ShipcallControlModel { #region Enumerations public enum TrafficLightMode { OFF, GREEN, YELLOW, RED, RED_YELLOW, ALL }; [Flags] public enum StatusFlags { RED, GREEN, YELLOW, BLINK_1, BLINK_2 }; #endregion public Shipcall? Shipcall { get; set; } public Ship? Ship { get; set; } public string? Agency { get; set; } public string? Berth { get; set; } public Dictionary AssignedParticipants { get; } = new(); public void AssignParticipants(List participants) { this.AssignedParticipants.Clear(); if (Shipcall != null) { foreach (int participantId in Shipcall.Participants) { foreach(Participant participant in participants) { if(participant.Id == participantId) AssignedParticipants[participant.Type] = participant; } } } } public TrafficLightMode LightMode { get { if(IsFlagSet(StatusFlags.RED)) { if(IsFlagSet((StatusFlags)StatusFlags.YELLOW)) { if(IsFlagSet(StatusFlags.GREEN)) { return TrafficLightMode.ALL; } return TrafficLightMode.RED_YELLOW; } return TrafficLightMode.RED; } if(IsFlagSet(StatusFlags.YELLOW)) return TrafficLightMode.YELLOW; if(IsFlagSet(StatusFlags.GREEN)) return TrafficLightMode.GREEN; return TrafficLightMode.OFF; } } internal string? GetParticipantNameForType(Extensions.ParticipantType participantType) { foreach(Participant p in AssignedParticipants.Values) { if (p.IsFlagSet(participantType)) return p.Name; } return null; } #region private helper private bool IsFlagSet(StatusFlags flag) { if(this.Shipcall == null) return false; return (this.Shipcall.Flags & (int) flag) != 0; } #endregion } }