using Microsoft.AspNetCore.Mvc;
using economy.Models;
using economy.Models.Exchange;
using economy.Models.Interest;
using economy.Models.International;

namespace economy.Controllers
{
    public class FinancialController : Controller
    {
        private readonly KoreaEximGoKR _koreaEximGoKR;
        private Dictionary<string, string> _queryString;

        public FinancialController(KoreaEximGoKR koreaEximGoKR)
        {
            _koreaEximGoKR = koreaEximGoKR;
        }

        // 환율
        public async Task<IActionResult> Exchange(Models.Exchange.Request request)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            ExchangeModel exchange = new ExchangeModel(_koreaEximGoKR);
            Models.Exchange.Response itemList = await exchange.GetExchange(request);

            var viewModel = new View<Models.Exchange.Request, Models.Exchange.Response>();
            viewModel.Request = request;
            viewModel.Response = itemList;

            return View(viewModel);
        }

        // 대출 금리
        public async Task<IActionResult> Interest(Models.Interest.Request request)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            InterestModel interest = new InterestModel(_koreaEximGoKR);
            Models.Interest.Response itemList = await interest.GetInterestRate(request);

            var viewModel = new View<Models.Interest.Request, Models.Interest.Response>();
            viewModel.Request = request;
            viewModel.Response = itemList;

            ViewData["type"] = "Interest";

            return View(viewModel);
        }

        // 국제 금리
        public async Task<IActionResult> International(Models.International.Request request)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            InternationalModel international = new InternationalModel(_koreaEximGoKR);
            Models.International.Response itemList = await international.GetInternationalRate(request);

            var viewModel = new View<Models.International.Request, Models.International.Response>();
            viewModel.Request = request;
            viewModel.Response = itemList;

            ViewData["type"] = "International";

            return View(viewModel);
        }
    }
}
