using MemberCenter.Application.Abstractions;
using MemberCenter.Application.Models.Admin;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace MemberCenter.Web.Areas.Admin.Controllers;

[Area("Admin")]
[Authorize(Policy = "Admin")]
[Route("admin/security")]
public class SecurityController : Controller
{
    private readonly ISecuritySettingsService _settingsService;

    public SecurityController(ISecuritySettingsService settingsService)
    {
        _settingsService = settingsService;
    }

    [HttpGet("")]
    public async Task<IActionResult> Index()
    {
        var settings = await _settingsService.GetAsync();
        return View(settings);
    }

    [HttpPost("")]
    public async Task<IActionResult> Save(SecuritySettingsDto model)
    {
        if (!ModelState.IsValid)
        {
            return View("Index", model);
        }

        await _settingsService.SaveAsync(model);
        ViewData["Result"] = "Saved";
        return View("Index", model);
    }
}
