<commit_before>﻿using System;
using System.Collections.Generic;

namespace Alamut.Data.Structure
{
    /// <summary>
    /// Represent Service result data structure
    /// It can be used as web service result
    /// </summary>
    /// <remarks>result for void Service</remarks>
    public class ServiceResult 
    {
        public string Message { get; set; }

        public bool Succeed { get; set; }

        /// <summary>
        /// return a successful ServiceResult 
        /// </summary>
        /// <returns>successful ServiceResult</returns>
        public static ServiceResult Okay(string message = "")
        {
            return new ServiceResult
            {
                Succeed = true,
                Message = message,
            };
        }


        /// <summary>
        /// return a ServiceResult with error status and error message
        /// </summary>
        /// <param name="message">error message</param>
        /// <returns>Error ServiceResult</returns>
        public static ServiceResult Error(string message = "")
        {
            return new ServiceResult
            {
                Succeed = false,
                Message = message,
            };
        }

        /// <summary>
        /// return a ServiceResult from exception
        /// most inmportant exception included in error message
        /// </summary>
        /// <param name="ex">the exception</param>
        /// <returns>Error ServiceResult</returns>
        public static ServiceResult Exception(Exception ex)
        {
            return new ServiceResult
            {
                Succeed = false,
                Message = ex.GetBaseException().Message,
            };
        }

        /// <summary>
        /// return a ServiceResult from validationResult 
        ///     that contains validation message in JSON fomat.
        /// </summary>
        /// <param name="fieldMessages">List of { propertyName, validationMessage }</param>
        /// <returns></returns>
        public static dynamic ValidationFailed(Dictionary<string, string> fieldMessages)
        {
            return new
            {
                Succeed = false,
                Message = fieldMessages
            };
        }
    }

    /// <summary>
    /// provides a generic data weapper for Service result 
    /// </summary>
    /// <typeparam name="T">data type of return</typeparam>
    /// <remarks>result for not void result</remarks>
    public class ServiceResult<T> : ServiceResult
    {
        public T Data { get; set; }

        /// <summary>
        /// returns a successful typed ServiceResult
        /// </summary>
        /// <param name="data">return data</param>
        /// <param name="message">the result message</param>
        /// <returns>successful ServiceResult</returns>
        public static ServiceResult<T> Okay(T data, string message = "")
        {
            return new ServiceResult<T>
            {
                Succeed = true,
                Message = message,
                Data = data,
            };
        }

        /// <summary>
        /// returns a typed ServiceResult with an error
        /// </summary>
        /// <param name="message">error message</param>
        /// <returns>error ServiceResult</returns>
        public new static ServiceResult<T> Error(string message)
        {
            return new ServiceResult<T>
            {
                Succeed = false,
                Message = message,
            };
        }

        /// <summary>
        /// return a ServiceResult from exception
        /// most inmportant exception included in error message
        /// </summary>
        /// <param name="ex">the exception</param>
        /// <returns>Error ServiceResult</returns>
        public new static ServiceResult<T> Exception(Exception ex)
        {
            return new ServiceResult<T>
            {
                Succeed = false,
                Message = ex.GetBaseException().Message
            };
        }
    }
}<commit_msg>add statusCode to ServiceResult.<commit_after>﻿using System;

namespace Alamut.Data.Structure
{
    /// <summary>
    /// Represent Service result data structure
    /// It can be used as web service result
    /// </summary>
    /// <remarks>result for void Service</remarks>
    public class ServiceResult 
    {
        public string Message { get; set; }
        public bool Succeed { get; set; }
        public int StatusCode { get; set; }

        /// <summary>
        /// return a successful ServiceResult 
        /// </summary>
        /// <returns>successful ServiceResult</returns>
        public static ServiceResult Okay(string message = "", int statusCode = 200)
        {
            return new ServiceResult
            {
                Succeed = true,
                Message = message,
                StatusCode = statusCode
            };
        }


        /// <summary>
        /// return a ServiceResult with error status and error message
        /// </summary>
        /// <param name="message">error message</param>
        /// <param name="statusCode"></param>
        /// <returns>Error ServiceResult</returns>
        public static ServiceResult Error(string message = "",int statusCode = 500)
        {
            return new ServiceResult
            {
                Succeed = false,
                Message = message,
                StatusCode = statusCode
            };
        }

        /// <summary>
        /// return a ServiceResult from exception
        /// most inmportant exception included in error message
        /// </summary>
        /// <param name="ex">the exception</param>
        /// <param name="statusCode"></param>
        /// <returns>Error ServiceResult</returns>
        public static ServiceResult Exception(Exception ex,int statusCode = 500)
        {
            return new ServiceResult
            {
                Succeed = false,
                Message = ex.ToString(),
                StatusCode = statusCode
            };
        }
        
    }

    /// <summary>
    /// provides a generic data weapper for Service result 
    /// </summary>
    /// <typeparam name="T">data type of return</typeparam>
    /// <remarks>result for not void result</remarks>
    public class ServiceResult<T> : ServiceResult
    {
        public T Data { get; set; }

        /// <summary>
        /// returns a successful typed ServiceResult
        /// </summary>
        /// <param name="data">return data</param>
        /// <param name="message">the result message</param>
        /// <param name="statusCode"></param>
        /// <returns>successful ServiceResult</returns>
        public static ServiceResult<T> Okay(T data, string message = "", int statusCode = 200)
        {
            return new ServiceResult<T>
            {
                Succeed = true,
                Message = message,
                Data = data,
                StatusCode = statusCode
            };
        }

        /// <summary>
        /// returns a typed ServiceResult with an error
        /// </summary>
        /// <param name="message">error message</param>
        /// <param name="statusCode"></param>
        /// <returns>error ServiceResult</returns>
        public new static ServiceResult<T> Error(string message,int statusCode = 500)
        {
            return new ServiceResult<T>
            {
                Succeed = false,
                Message = message,
                StatusCode = statusCode
            };
        }

        /// <summary>
        /// return a ServiceResult from exception
        /// most inmportant exception included in error message
        /// </summary>
        /// <param name="ex">the exception</param>
        /// <param name="statusCode"></param>
        /// <returns>Error ServiceResult</returns>
        public new static ServiceResult<T> Exception(Exception ex,int statusCode = 500)
        {
            return new ServiceResult<T>
            {
                Succeed = false,
                Message = ex.ToString(),
                StatusCode = statusCode
            };
        }
    }
}
{'fraction_non_alphanumeric': 0.11153467781603542, 'fraction_numerical': 0.0022134776192818495, 'mean_word_length': 1.4818431492218493, 'pattern_counts': {'":': 0, '<': 126, '<?xml version=': 0, '>': 126, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2390179', 'n_tokens_mistral': 1962, 'n_tokens_neox': 1893, 'n_words': 550}