namespace MvcInsert.Utility.ActionResults
{
    using System;
    using System.Web;
    using System.Web.Mvc;

    /// <summary>
    ///     The CSS action result.
    /// </summary>
    public class CssResult : ActionResult
    {
        /// <summary>
        ///     Initializes a new instance of the <see cref="CssResult" /> class.
        /// </summary>
        /// <param name="stylesheet">
        ///     The script.
        /// </param>
        public CssResult(string stylesheet)
        {
            Stylesheet = stylesheet;
        }

        /// <summary>
        ///     Gets the style-sheet.
        /// </summary>
        /// <value>
        ///     The style-sheet.
        /// </value>
        public string Stylesheet { get; private set; }

        /// <summary>
        ///     Adds the given style-sheet to the <see cref="HttpResponseBase" /> of the given
        ///     <see cref="ControllerContext" />.
        /// </summary>
        /// <param name="context">
        ///     The <see cref="ControllerContext" />.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="context" /> is null.
        /// </exception>
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            HttpResponseBase response = context.HttpContext.Response;

            response.ContentType = "text/css";

            if (Stylesheet != null)
            {
                response.Write(Stylesheet);
            }
        }
    }
}