using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Discord;

namespace JellyfinRPC
{
    class DiscordRPC
    {
        public static Int64 discordAppID = Int64.Parse(ConfigManager.GetEntry("DiscordClientID"));
        

        public static void UpdateActivity(Discord.Discord discord)
        {
            var activityManager = discord.GetActivityManager();
            string[] RPCVari = JellyfinAPI.Jellyfin().Result.Split('|');
            if (JellyfinAPI.Jellyfin().Result != null)
            {
                Activity activity = new Activity
                {
                    Details = RPCVari.GetValue(int.Parse("2")).ToString(),
                    State = RPCVari.GetValue(int.Parse("3")).ToString(),
                    Timestamps =
                    {
                        Start = Utils.DateTimeInUnix(DateTime.Now) - Utils.DateTimeInUnix(DateTime.Parse(RPCVari.GetValue(int.Parse("5")).ToString())),
                        End = Utils.DateTimeInUnix(DateTime.Now) + (Utils.DateTimeInUnix(DateTime.Parse(RPCVari.GetValue(int.Parse("4")).ToString())) - Utils.DateTimeInUnix(DateTime.Parse(RPCVari.GetValue(int.Parse("5")).ToString())))
                    },
                    Assets =
                    {
                        LargeImage = RPCVari.GetValue(int.Parse("0")).ToString(),
                        LargeText = RPCVari.GetValue(int.Parse("1")).ToString()
                    }
                };
                StatusManager.WriteStatusLine($"Details: {RPCVari.GetValue(int.Parse("2"))}, State:{RPCVari.GetValue(int.Parse("3"))}");
                activityManager.UpdateActivity(activity, result => ConsoleManager.WriteToConsole($"Updating Presence. Details: {activity.Details}, State: {activity.State}, Result: {result}"));
            }
            else
            {
                activityManager.ClearActivity(result => ConsoleManager.WriteToConsole($"Update Activity {result}"));
            }
        }
    }
}
