using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Nirvana.Common;
using Nirvana.Common.ApiBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Furion.DependencyInjection;
using Waste.Domain;

namespace Waste.Web.Entry
{
    /// <summary>
    /// 基础定义,需要权限的都引用此类
    /// </summary>
    [HandlerLogin]
    public class BaseModel : PageModel
    {
        public OperatorModel Baseuser = OperatorProvider.Provider.GetCurrent();
        protected virtual JsonResult ResultJson(int code, string message, object data)
        {
            return new JsonResult(new
            {
                code = code,
                message = message,
                data = data
            });
        }

        protected virtual JsonResult ResultJson(ResultInfo data)
        {
            return new JsonResult(new
            {
                code = data.code,
                message = data.message,
                data = data.data
            });
        }

        protected virtual JsonResult Success(object data)
        {
            return new JsonResult(new
            {
                code = ResultState.SUCCESS,
                message = "success",
                data = data
            });
        }

        protected virtual JsonResult SuccessMessage(string message)
        {
            return new JsonResult(new
            {
                code = ResultState.SUCCESS,
                message = message
            });
        }

        public virtual JsonResult Fail(string message)
        {
            message = string.IsNullOrEmpty(message) ? "请求失败" : message;
            return new JsonResult(new
            {
                code = ResultState.FAIL,
                message = message
            });
        }
    }

    public class CurrentUser : ICurrentUser, ITransient
    {
        public Guid? Id => OperatorProvider.Provider.GetCurrent()?.UserId;
    }
}
