﻿using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Mvc;

namespace Personalization.Drivers
{
    public class HttpErrorData
    {
        public HttpStatusCode StatusCode { get; set; }
        public string Message { get; set; }

        public HttpErrorData(HttpStatusCode statusCode, string message)
        {
            StatusCode = statusCode;
            Message = message;
        }

        public static HttpErrorData NotFound()
        {
            return new HttpErrorData(HttpStatusCode.NotFound, "The resource could not be found");
        }

        public HttpStatusCodeResult ToHttpStatusResult()
        {
            return new HttpStatusCodeResult(StatusCode, Message);
        }

        public void ThrowForRequest(HttpRequestMessage request)
        {
            var errorResponse = request.CreateErrorResponse(StatusCode, Message);
            throw new HttpResponseException(errorResponse);
        }
    }
}