using System.Collections.Generic;
using Newtonsoft.Json;
using Pixiview.Illust;

namespace Pixiview.Utils
{
    public class IllustResponse<T>
    {
        public bool error;
        public string message;
        public T body;
    }

    public class Illust
    {
        public string illustId;
        public string illustTitle;
        public string id;
        public string title;
        public string url;
        public string description;
        public string[] tags;
        public string userId;
        public string userName;
        public int width;
        public int height;
        public int pageCount;
        public string alt;
        public IllustUrls urls;
        public string seriesId;
        public string seriesTitle;
        public string profileImageUrl;
        public int xRestrict;

        public class IllustUrls
        {
            [JsonProperty("250x250")]
            public string x250;
            [JsonProperty("360x360")]
            public string x360;
            [JsonProperty("540x540")]
            public string x540;
        }

        public IllustItem ConvertToItem()
        {
            return new IllustItem
            {
                Id = illustId,
                ImageUrl = urls?.x360 ?? url,
                Title = illustTitle,
                IsRestrict = xRestrict == 1,
                ProfileUrl = profileImageUrl,
                UserId = userId,
                UserName = userName,
                Width = width,
                Height = height,
                PageCount = pageCount
            };
        }
    }

    public class IllustData : IllustResponse<IllustBody> { }
    public class IllustBody
    {
        public Page page;
        public Thumbnail thumbnails;
        public User[] users;

        public class Page
        {
            public int[] follow;
            public string[] recommend;
            public RecommendByTag[] recommendByTags;
            public Ranking ranking;
            public RecommendUser[] recommendUser;
            public EditorRecommend[] editorRecommend;
            public string[] newPost;

            public class RecommendByTag
            {
                public string tag;
                public string[] ids;
            }

            public class Ranking
            {
                public RankingItem[] items;
                public string date;

                public class RankingItem
                {
                    public string rank;
                    public string id;
                }
            }

            public class RecommendUser
            {
                public int id;
                public string[] illustIds;
            }

            public class EditorRecommend
            {
                public string illustId;
                public string comment;
            }
        }

        public class Thumbnail
        {
            public Illust[] illust;
        }

        public class User
        {
            public string userId;
            public string name;
            public string image;
            public string imageBig;
            public bool premium;
            public bool isFollowed;
            public string background;
            public int partial;
        }
    }

    public class IllustPageData : IllustResponse<IllustPageBody[]> { }
    public class IllustPageBody
    {
        public Urls urls;
        public int width;
        public int height;

        public class Urls
        {
            public string thumb_mini;
            public string small;
            public string regular;
            public string original;
        }
    }

    public class IllustUserListData : IllustResponse<IllustUserListBody> { }
    public class IllustUserListBody
    {
        public Dictionary<string, object> illusts;
    }

    public class IllustUserData : IllustResponse<IllustUserBody> { }
    public class IllustUserBody
    {
        public Dictionary<string, Illust> works;
    }
}
