using RMYY_CallCenter_Api.Models;
using RMYY_CallCenter_Api.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace RMYY_CallCenter_Api.Controllers
{
    public class BaseController : Controller
    {
        public new Model.T_Sys_UserAccount User
        {
            get
            {
                try
                {
                    var us = (FormsPrincipal<Model.T_Sys_UserAccount>)base.User;

                    return us.UserData;
                }
                catch
                {
                    return null;
                }
            }
        }
        /// <summary>
        /// 成功的消息格式化
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        protected virtual ActionResult Success(string message)
        {
            var jsonMsg = new AjaxResult { state = ResultTypes.success.ToString(), message = message }.ToJson();
            return Content(jsonMsg);
        }

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

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

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

        /// <summary>
        /// 错误的消息格式化
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        protected virtual ActionResult Warn(string message)
        {
            var jsonMsg = new AjaxResult { state = ResultTypes.warning.ToString(), message = message }.ToJson();
            return Content(jsonMsg);
        }
        /// <summary>
        /// 警告的消息格式化
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        protected virtual ActionResult Warn(string message, object data)
        {
            var jsonMsg = new AjaxResult { state = ResultTypes.warning.ToString(), message = message, data = data }.ToJson();
            return Content(jsonMsg);
        }


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

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