using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace HttpClientStudy.WebApp.Controllers
{
    /// <summary>
    /// 简单接口 控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class HelloController  : ControllerBase
    {
        private ILogger<HelloController > _logger;

        /// <summary>
        /// 构造
        /// </summary>
        public HelloController (ILogger<HelloController > logger)
        { 
            _logger = logger;
        }

        /// <summary>
        /// Ping
        /// </summary>
        /// <returns>Pong</returns>
        [HttpGet]
        public IActionResult Ping()
        {
            return Ok("Pong");
        }

        /// <summary>
        /// Index
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Index()
        {
            return Ok("Index");
        }

        /// <summary>
        /// Get请求
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Get()
        {
            return Ok("Hello, world!");
        }

        /// <summary>
        /// Get请求
        /// </summary>
        /// <returns>
        /// json对象
        /// </returns>
        [HttpGet]
        public IActionResult GetAccount()
        {
            var account = new Account()
            { 
                Id = 1,
                Name = "Hello",
                Password = "pwd",
                Role = "Devlopment"

            };

            return new JsonResult(account);
        }

        /// <summary>
        /// Post 请求
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Post()
        {
            return Ok("Post Success");
        }

        /// <summary>
        /// Post 请求:添加账号
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AddAccount([FromBody] Account vm)
        {
            return Ok("添加成功");
        }
    }
}