using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using FMSAdmin.Models;
using System.Security.Claims;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using FMSAdmin.Data;
using System.Net.Http;
using System.Xml.Linq;
using FMSAdmin.Helpers;
using FMSAdmin.Entities;
using System.ComponentModel.DataAnnotations;
using System.Net;
using FMSAdmin.Services;

namespace FMSAdmin.Controllers {
    [Authorize]
    [ApiController]
    [ApiVersion("1")]
    [Route("api/[controller]")]
    public class SiteWeatherInfoController : Controller {
        private readonly ILogger<SiteWeatherInfoController> _logger;
        private readonly FMSContext _context;
        private readonly SiteWeatherInfoService _service;

        public SiteWeatherInfoController(
            ILogger<SiteWeatherInfoController> logger,
            FMSContext context,
            SiteWeatherInfoService service
            ) {
            _logger = logger;
            _context = context;
            _service = service;
        }

        [HttpGet]
        public IActionResult Api(int? siteId, string sido, string sigun) {
            if (siteId == null) {
                siteId = User.GetSiteId();
            }
            var weatherInfo = _service.GetInfo(siteId.Value, sido, sigun);

            return Ok(weatherInfo);
        }

        [AllowAnonymous]
        [HttpGet("[action]")]
        public IActionResult NxNyList() {
            var list = _context.WeatherRegionNxNy.ToList();

            return Ok(list);
        }

        [AllowAnonymous]
        [HttpGet("[action]")]
        public IActionResult WeatherStat() {
            var table = _service.WeatherStat();

            return Ok(table);
        }
    }
}
