using Microsoft.AspNetCore.Http;
using System;
using System.Text.Json.Serialization;

namespace collAnon.Pub.Shared
{
	public class WebResult
	{
		public WebResult Invalidate<T>(string errorMessage, int statusCode = StatusCodes.Status400BadRequest, Exception exception = null, T defaultData = default)
		{
			IsValid = false;
			ErrorMessage = errorMessage;
			StatusCode = statusCode;
			Exception = exception;
			Data = defaultData;
			return this;
		}
		public WebResult Invalidate(string errorMessage, int statusCode = StatusCodes.Status400BadRequest, Exception exception = null)
		{
			IsValid = false;
			ErrorMessage = errorMessage;
			StatusCode = statusCode;
			Exception = exception;
			return this;
		}

		public WebResult Invalidate(WebResult result)
		{
			IsValid = result.IsValid;
			ErrorMessage = result.ErrorMessage;
			StatusCode = result.StatusCode;
			Exception = result.Exception;
			Data = result.Data;
			return this;
		}

		public int StatusCode { get; set; } = StatusCodes.Status200OK;
		public string ErrorMessage { get; set; }

		public bool IsValid { get; set; } = true;
		[JsonIgnore]
		public object Data { get; set; }
		[JsonIgnore]
		public Exception Exception { get; set; }
	}

}
