using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Caching.Distributed;
using Api.SignToken;
using Microsoft.Extensions.Logging;
using MadRunFabric.Common;

namespace SignTokenApi.Controllers
{
    [Authorize]
    [Route("api/[controller]")]
    public class ValuesController : BaseController
    {

        private readonly IConfiguration _configuration;
        private readonly IDistributedCache _cache;
        private static IPermissionService _permissionService;
        private readonly ILogger<ValuesController> _logger;

        public ValuesController(IConfiguration configuration, IDistributedCache cache, IPermissionService permissionService, ILogger<ValuesController> logger)
        {
            _configuration = configuration;
            _cache = cache;
            _permissionService = permissionService;
            _logger = logger;
        }

        [HttpGet("auth")]
        //[PermissionFilter(Permissions.UserUpdate, _permissionService.GetPermissionAsync().Result.ToObject<List<Permission>>())]
        [PermissionFilter(Operations.UserUpdate)]
        public IActionResult Auth()
        {
            _cache.SetStringAsync("name", System.DateTime.Now.ToString());

            return new JsonResult(new
            {
                Status = false,
                Message = "认证失败1111111111111111111111111111111111"
            });
        }


        [AllowAnonymous]
        [HttpGet("getpermission")]
        public string GetPermission()
        {
            var permission = new List<Permission> {
                              new Permission {  Type="User.Create", Name="system"},
                              new Permission {  Type="User.Read", Name="system"}
                          };
            return permission.ToJson();
        }

        // GET api/values
        [AllowAnonymous]
        [HttpGet]
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "option1 = 打滴滴" };
        }

        [HttpGet("get5")]
        public IEnumerable<string> Get5()
        {
            return Get();
        }



        //// GET api/values/5
        //[HttpGet("{id}")]
        //public string Get(int id)
        //{
        //    return "value";
        //}

        // POST api/values
        [HttpPost]
        public void Post([FromBody]string value)
        {
        }

        // PUT api/values/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE api/values/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }
}
