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.Logging;
using Api.SignToken;
using Pivotal.Discovery.Client;
using System.Net.Http;
using MadRunFabric.Common;

namespace CallCenterApi.Controllers
{
    [Authorize]
    [Route("api/[controller]")]
    public class ValuesController : BaseController
    {
        private readonly ILogger<ValuesController> _logger;
        private readonly IPermissionService _permissionService;
        private readonly ISignTokenService _signTokenService;
        private readonly IConfiguration _configuration;

        //private readonly DiscoveryHttpClientHandler _handler;
        //private const string ProductUrl = "http://product/api/values";


        public ValuesController(ILogger<ValuesController> logger,IConfiguration configuration,IPermissionService permissionService, ISignTokenService signTokenService)
        {
            _logger = logger;
            _configuration = configuration;
            _permissionService = permissionService;
            _signTokenService = signTokenService;
        }

        // GET api/values
        [HttpGet]
        [AllowAnonymous]
        public string Get()
        {
            //_logger.LogInformation("加载成功");
            //_logger.LogError("错误测试");
            return "sdfsdfsdfsdfsd";
        }


        [HttpGet("get4")]
        [AllowAnonymous]
        public string Get4Async()
        {
            return  _signTokenService.GetInfo();
        }

        [HttpGet("get5")]
        [AllowAnonymous]
        public async Task<string> Get5Async()
        {
            return await _signTokenService.Wechat_LoginAsync("9876","yuqian","url");
        }

        //[MapToApiVersion("1.0")]
        //[HttpGet("get5")]
        //[AllowAnonymous]
        //public string Get5()
        //{
        //    //var client = new HttpClient(_handler);
        //    //return  client.GetStringAsync(ProductUrl).Result;
        //}


        [HttpGet("get2"),MapToApiVersion("2.0"),MapToApiVersion("1.0")]
        public IEnumerable<string> Get2()
        {
            _logger.LogInformation("加载成功");
            return new string[] { "value2", $"option1 = {_configuration["Data"]}" };
        }

        [Authorize]
        [HttpGet("get1")]
        public IEnumerable<string> Get1()
        {
         
            return new string[] { User.Identity.Name, $"option1 = {_configuration["Data"]}" };
        }

        // 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)
        {
        }
    }
}
