using Knoks.Api.Controllers.Base;
using Knoks.Api.Entities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;
using static Knoks.Api.Authentication.IdentityConsts;

namespace Knoks.Api.Controllers
{
    [Route("v1/[controller]")]
    public class PingController : ApiConsumerController
    {
        private readonly ILogger<PingController> _logger;

        public PingController(ILogger<PingController> logger)
        {
            _logger = logger;
        }

        [AllowAnonymous]
        [HttpGet("")]
        [HttpGet("/")]
        public async Task<Pong> Ping([FromQuery]string info)
        {
            return await Task.FromResult(new Pong { Value = info });
        }

        [HttpGet("OptionalUser")]
        public async Task<Pong> OptionalUser()
        {
            return await Task.FromResult(new Pong { Value = ContextUserId });
        }

        [Authorize(ApiUserPolicy)]
        [HttpGet("MandatoryUser")]
        public async Task<Pong> MandatoryUser()
        {
            return await Task.FromResult(new Pong { Value = ContextUserId.Value });
        }
    }
}
