using System;
using System.Collections.Generic;
using System.Text;

namespace Apewer.Web
{

    /// <summary>缓存控制的值。</summary>
    public static class CacheControl
    {

        /// <summary>不缓存。</summary>
        public const string Disabled = "no-cache, no-store, must-revalidate";

        /// <summary>1 天的秒数。</summary>
        public const int Day = 86400;

        /// <summary>30 天的秒数。</summary>
        public const int Month = 259200;

        /// <summary>365 天的秒数。</summary>
        public const int Year = 31536000;

        /// <summary>构建缓存指令,此指令允许所有缓存。</summary>
        /// <param name="maxAge">浏览器的缓存秒数。</param>
        /// <param name="sMaxAge">代理服务器的缓存秒数。</param>
        public static string Public(int maxAge, int sMaxAge)
        {
            if (maxAge < 0) throw new ArgumentOutOfRangeException(nameof(maxAge));
            if (sMaxAge < 0) throw new ArgumentOutOfRangeException(nameof(sMaxAge));
            return $"public, max-age={maxAge}, s-maxage={sMaxAge}, must-revalidate";
        }

        /// <summary>构建缓存指令,此指令仅允许浏览器缓存。</summary>
        /// <param name="maxAge">浏览器的缓存秒数。</param>
        public static string Private(int maxAge)
        {
            if (maxAge < 0) throw new ArgumentOutOfRangeException(nameof(maxAge));
            return $"private, max-age={maxAge}, must-revalidate";
        }

    }

}