using System;

namespace YGNT.Infrastructure.AbpEntity
{
    public class CheckResult
    {
        /// <summary>
        /// 是否通过
        /// </summary>
        public bool IsPass { get; internal set; }

        /// <summary>
        /// 消息
        /// </summary>
        public string Message { get; set; }

        public CheckResult(string message)
        {
            Message = message;
        }

        public CheckResult()
        {
        }

        public static CheckResult Failed(string message)
        {
            return new CheckResult(message);
        }

        public static CheckResult Succeed(string message = null)
        {
            return new CheckOkResult() { Message = message };
        }

    }

    public class CheckOkResult : CheckResult
    {
        public CheckOkResult()
        {
            IsPass = true;
        }
    }


    public static class CheckResultEx
    {
        /// <summary>
        /// 如果没有通过检查 将错误信息抛出
        /// </summary>
        /// <param name="result"></param>
        public static void ThrowException(this CheckResult result)
        {
            if (!result.IsPass)
            {
                throw new Exception(result.Message);
            }
        }
    }
}