using Microsoft.AspNetCore.Mvc;
using economy.Models;
using economy.Models.Financial;
using Exchange = economy.Models.Financial.Exchange;
using Interest = economy.Models.Financial.Interest;
using International = economy.Models.Financial.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(Exchange.Request request)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

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

            await exchange.GetExchangeValue();

            return View(viewModel);
        }

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

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

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

            ViewData["type"] = "Interest";

            return View(viewModel);
        }

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

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

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

            ViewData["type"] = "International";

            return View(viewModel);
        }
    }
}
