﻿using System;
using Newtonsoft.Json;

namespace ErgastApi.Responses
{
    // TODO: Use internal/private constructors for all response types?
    public abstract class ErgastResponse
    {
        [JsonProperty("url")]
        public virtual string RequestUrl { get; private set; }

        [JsonProperty("limit")]
        public virtual int Limit { get; private set; }

        [JsonProperty("offset")]
        public virtual int Offset { get; private set; }

        [JsonProperty("total")]
        public virtual int TotalResults { get; private set; }

        // TODO: Note that it can be inaccurate if limit/offset do not correlate
        // TODO: Test with 0 values
        public virtual int Page => Offset / Limit + 1;

        // TODO: Test with 0 values
        public virtual int TotalPages => (int) Math.Ceiling(TotalResults / (double)Limit);

        // TODO: Test
        public virtual bool HasMorePages => TotalResults > Limit + Offset;
    }
}

﻿using System;
using Newtonsoft.Json;

namespace ErgastApi.Responses
{
    // TODO: Use internal/private constructors for all response types?
    public abstract class ErgastResponse
    {
        [JsonProperty("url")]
        public string RequestUrl { get; protected set; }

        [JsonProperty("limit")]
        public int Limit { get; protected set; }

        [JsonProperty("offset")]
        public int Offset { get; protected set; }

        [JsonProperty("total")]
        public int TotalResults { get; protected set; }

        // TODO: Note that it can be inaccurate if limit/offset do not divide evenly
        public int Page
        {
            get
            {
                if (Limit <= 0)
                    return 1;

                return (int) Math.Ceiling((double) Offset / Limit) + 1;
            }
        }

        // TODO: Test with 0 values
        public int TotalPages => (int) Math.Ceiling(TotalResults / (double) Limit);

        // TODO: Test
        public bool HasMorePages => TotalResults > Limit + Offset;
    }
}

Fix issue with Page calculation
Fix issue with Page calculation
