using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using Newtonsoft.Json;

namespace ChatController.LoginKlassen
{
    /// <summary>
    /// Konvertiertes Objekt vom Server mit den Gruppen, Meldungen, Fehlern und ob die Abfragen an den Server erfolgreich war
    /// </summary>
    public class ChatGruppenDaten
    {
        public ChatGruppenDatenResponse Response { get; set; }
    }

    public class GroupInput
    {
        public int Oid { get; set; }
        public string Name { get; set; }
        public string Avatar { get; set; }
        public string Mobile { get; set; }
        public GroupLatestMessage LastMessage { get; set; }
        public GroupUsers[] Users { get; set; }
        public bool OnlyEmployees { get; set; }

        [JsonProperty("accent_color")]
        public string AccentColor { get; set; }

        [DefaultValue(true)]
        [JsonProperty("i_can_write", DefaultValueHandling = DefaultValueHandling.Populate)]
        public bool CanWrite { get; set; }

        [JsonProperty("i_can_see_participants")]
        public bool CanSeeParticipants { get; set; }
    }

    public class GroupLatestMessage
    {
        public long Id { get; set; }

        private string _Text;
        public string Text
        {
            get
            {
                var result = _Text;

                if (string.IsNullOrEmpty(_Text) && !string.IsNullOrEmpty(File))
                {
                    result = Path.GetFileName(File);
                }

                if (!string.IsNullOrEmpty(_Text) && _Text.Length > 25)
                {
                    result = _Text.Substring(0, 25) + "...";
                }

                return result;
            }

            set => _Text = value;
        }

        public string File { get; set; }
        public string OriginalFileName { get; set; }
        public string SmallerImage { get; set; }
        public LastMessageTimeStamp Timestamp { get; set; }
        public long CreatedAt { get; set; }
        public long UserId { get; set; }
        public string UserIdManage { get; set; }
        public string UserName { get; set; }
        public string UserPicture { get; set; }
        public string GroupId { get; set; }
    }

    public class GroupUsers
    {
        public long Oid { get; set; }
        public string Userid_Manage { get; set; }
        public string Firstname { get; set; }
        public string Lastname { get; set; }
        public string Mobile { get; set; }
        public string Picture { get; set; }
        public bool Is_Employee { get; set; }
    }

    public class LastMessageTimeStamp
    {
        public string Date { get; set; }
        public int TimeZoneType { get; set; }
        public string TimeZone { get; set; }
    }

    public class ChatGruppenDatenResponse
    {
        public List<GroupInput> Groups { get; set; }
    }
}
