﻿// Copyright (c) 2018 Nikolay Zahariev <zahasoft.com>. Licensed under the MIT License.

namespace Zahasoft.Guard.Controllers
{
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Authorization;
    using Microsoft.AspNetCore.Mvc;
    using Zahasoft.Guard.Term;
    using Zahasoft.Guard.Term.Details;

    /// <summary>
    /// Terms and conditions controller.
    /// </summary>
    [Route(ControllerRoute.TermDetails)]
    public class TermDetailsController : BaseController
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="TermDetailsController"/> class.
        /// </summary>
        /// <param name="reader">Terms details reader</param>
        public TermDetailsController(ITermDetailsReader<TermModel> reader)
        {
            Details = reader;
        }

        /// <summary>
        /// Gets terms details reader.
        /// </summary>
        protected ITermDetailsReader<TermModel> Details { get; }

        /// <summary>
        /// Returns view with terms details.
        /// </summary>
        /// <returns>View</returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> Index()
        {
            return View(await Details.ReadAsync(new TermDetailsRequest()));
        }
    }
}