using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using ServiceWechat.Utility;

namespace ServiceWechat.Api.Controllers.Base
{
    public class BaseController : Controller
    {
        /// <summary>
        /// 成功的消息格式化
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        protected virtual JsonResult Success(string message)
        {
            var jsonMsg = new AjaxResult { state = ResultTypes.success.ToString(), message = message };

            return new JsonResult(jsonMsg);
        }

        /// <summary>
        /// 成功的消息格式化
        /// </summary>
        /// <param name="message"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        protected virtual JsonResult Success(string message, object data)
        {
            var jsonMsg = new AjaxResult { state = ResultTypes.success.ToString(), message = message, data = data };

            return new JsonResult(jsonMsg);
        }

        /// <summary>
        /// 跳转的消息格式化
        /// </summary>
        /// <param name="message"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        protected virtual JsonResult Redirect(string message, object data)
        {
            return new JsonResult(new AjaxResult { state = ResultTypes.redirect.ToString(), message = message, data = data });
        }

        /// <summary>
        /// 错误的消息格式化
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        protected virtual JsonResult Error(string message)
        {
            var jsonMsg = new AjaxResult { state = ResultTypes.error.ToString(), message = message };
            return new JsonResult(jsonMsg);
        }

        /// <summary>
        /// 未登录或者登录已过期
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        protected virtual JsonResult NoToken(string message)
        {
            var jsonMsg = new AjaxResult { state = ResultTypes.notoken.ToString(), message = message };
            return new JsonResult(jsonMsg);
        }

        /// <summary>
        /// 未授权
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        protected virtual JsonResult UnAuthorized(string message)
        {
            var jsonMsg = new AjaxResult { state = ResultTypes.unauthorized.ToString(), message = message };
            return new JsonResult(jsonMsg);
        }
    }
}
