// Copyright (c) 2023 schick Informatik // Description: Container model for shipcall related info // using BreCalClient.misc.Model; using System; using System.Collections.Generic; 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 #region Properties public Shipcall? Shipcall { get; set; } public Ship? Ship { get; set; } public string? Berth { get; set; } internal Dictionary AssignedParticipants { get; } = new(); public List Times { get; set; } = new(); 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; } } #endregion #region public methods public void AssignParticipants() { this.AssignedParticipants.Clear(); if (Shipcall != null) { foreach (ParticipantAssignment participantAssignment in Shipcall.Participants) { AssignedParticipants[(Extensions.ParticipantType)participantAssignment.Type] = participantAssignment; } } } internal Times? GetTimesForParticipantType(Extensions.ParticipantType type) { if (AssignedParticipants.ContainsKey(type)) { int participantId = AssignedParticipants[type].ParticipantId; foreach (Times times in this.Times) { if ((times.ParticipantId == participantId) && (times.ParticipantType == (int) type)) return times; } if(type == Extensions.ParticipantType.AGENCY) { // if I am BSMD and no agency entry was found this means we are editing the agency entry if(App.Participant.Type == (int) Extensions.ParticipantType.BSMD) { foreach(Times times in this.Times) { if ((times.ParticipantId == App.Participant.Id) && (times.ParticipantType == (int) Extensions.ParticipantType.AGENCY)) return times; } } } } return null; } public bool ContainsRemarkText(string text) { if(Shipcall != null) { foreach(Times times in this.Times) { if (times.Remarks == null) continue; if(times.Remarks.Contains(text)) return true; } } return false; } #endregion #region helper internal Participant? GetParticipantForType(Extensions.ParticipantType participantType) { if(AssignedParticipants.ContainsKey(participantType) && BreCalLists.ParticipantLookupDict.ContainsKey(AssignedParticipants[participantType].ParticipantId)) return BreCalLists.ParticipantLookupDict[AssignedParticipants[participantType].ParticipantId]; return null; } private bool IsFlagSet(StatusFlags flag) { if(this.Shipcall == null) return false; return (this.Shipcall.Flags & (int) flag) != 0; } #endregion } }