using System.Text.Json.Serialization;

namespace Insight.Infrastructure.Models
{
    public class PagedList<T>
    {
        public PagedMetaData Meta { get; } = new();
        public IEnumerable<T> Data { get; }

        public PagedList(IEnumerable<T> data, int offset, int limit, long total)
        {
            Data = data;
            Meta = new()
            {
                Offset = offset,
                Limit = limit,
                Count = data?.Count() ?? 0,
                Total = total,
            };
        }
    }

    public class PagedDataRequest
    {
        [JsonPropertyName("offset")]
        public int Offset { get; set; } = 0;

        [JsonPropertyName("limit")]
        public int Limit { get; set; } = 10;
    }

    public class PagedHeaderData : PagedDataRequest
    {
        [JsonPropertyName("count")]
        public int Count { get; set; } = 0;

        [JsonPropertyName("total")]
        public long Total { get; set; } = 0;
    }

    public class PagedMetaData : PagedHeaderData
    {
        [JsonPropertyName("next")]
        public string? Next { get; set; }

        [JsonPropertyName("previous")]
        public string? Previous { get; set; }
    }
}