using System;
using Common;
using Common.Constant;
using Common.Http;
using Esim.Apis.Business;
using Database.Database;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace RevoSystem.Apis.Controllers
{
    [ApiController]
    public class ArticleController : Controller
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(
            typeof(ArticleController)
        );

        ModelContext dbContext;
        IConfiguration configuration;

        IArticleBusiness articleBusiness;

        public ArticleController(
            IConfiguration _configuration,
            IArticleBusiness articleBusiness,
            ModelContext dbContext
        )
        {
            configuration = _configuration;
            this.articleBusiness = articleBusiness;
            this.dbContext = dbContext;
        }

        private string GetParameter(string key)
        {
            return configuration.GetSection(key).Value ?? "";
        }

        #region Article Endpoints

        /// <summary>
        /// Load article categories with pagination
        /// POST /apis/article/category
        /// </summary>
        [HttpPost]
        [Route(ApiUrlConstant.ArticleCategoryUrl)]
        public async Task<IActionResult> ArticleCategory([FromBody] ArticleCategoryReq request)
        {
            return await articleBusiness.ArticleCategory(HttpContext.Request, request);
        }

        /// <summary>
        /// Load articles with pagination and filters
        /// POST /apis/article/load
        /// </summary>
        [HttpPost]
        [Route(ApiUrlConstant.ArticleLoadUrl)]
        public async Task<IActionResult> ArticleLoad([FromBody] ArticleLoadReq request)
        {
            return await articleBusiness.ArticleLoad(HttpContext.Request, request);
        }

        /// <summary>
        /// Get article detail by ID or slug
        /// POST /apis/article/detail
        /// </summary>
        [HttpPost]
        [Route(ApiUrlConstant.ArticleDetailUrl)]
        public async Task<IActionResult> ArticleDetail([FromBody] ArticleDetailReq request)
        {
            return await articleBusiness.ArticleDetail(HttpContext.Request, request);
        }

        #endregion
    }
}
