namespace Tiobon.Core.Controllers;

/// <summary>
/// 公共服务
/// </summary>
[Produces("application/json")]
[Route("api/Common")]
[Authorize(Permissions.Name), ApiExplorerSettings(GroupName = Grouping.GroupName_System)]
public class CommonController : BaseApiController
{
    private readonly ILogger<TiobonController> _logger;
    private readonly ICommonServices _commonServices;

    /// <summary>
    /// 构造函数
    /// </summary> 
    /// <param name="logger"></param>
    /// <param name="commonServices"></param>
    public CommonController(ILogger<TiobonController> logger, ICommonServices commonServices)
    {
        _commonServices = commonServices;
        _logger = logger;
    }

    #region 获取菜单
    /// <summary>
    /// 获取菜单
    /// </summary>
    /// <param name="param"></param>
    /// <returns></returns>
    [HttpPost, Route("GetMenu")]
    public async Task<ServiceResult<MenuReturn>> GetMenuAsync([FromBody] MenuParam param)
    {
        return await _commonServices.GetMenuAsync(param);
    }
    #endregion

    #region 获取模块信息接口
    /// <summary>
    /// 获取模块信息接口
    /// </summary>
    /// <param name="param"></param>
    /// <returns></returns>
    [HttpPost, Route("GetModuleInfo")]
    public async Task<ServiceResult<ModuleReturn>> GetModuleInfoAsync([FromBody] ModuleParam param)
    {
        return await _commonServices.GetModuleInfoAsync(param);
    }
    #endregion

    #region 获取模块信息接口
    /// <summary>
    /// 获取模块信息接口
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    [HttpPost, Route("GetSelect/{type}")]
    public async Task<ServiceResult<CommonSelect>> GetSelectAsync(string type, string Keywords)
    {
        return await _commonServices.GetSelectAsync(type, Keywords);
    }
    #endregion

    #region 导出Excel
    /// <summary>
    /// 导出Excel
    /// </summary>
    /// <param name="param"></param>
    /// <returns></returns>
    [HttpPost, Route("ExportExcel")]
    public async Task<ServiceResult<QueryExportReturn>> ExportExcelAsync([FromBody] QueryExport param)
    {
        return await _commonServices.ExportExcelAsync(param);
    }
    #endregion

    #region 下载导入模板Excel
    /// <summary>
    /// 下载导入模板Excel
    /// </summary>
    /// <param name="param"></param>
    /// <returns></returns>
    [HttpPost, Route("DownImportTemplate")]
    public async Task<ServiceResult<QueryExportReturn>> DownImportTemplateAsync([FromBody] QueryExport param)
    {
        return await _commonServices.DownImportTemplateAsync(param);
    }
    #endregion

    #region Excel导入
    /// <summary>
    /// Excel导入
    /// </summary>
    /// <param name="file">文件</param>
    /// <param name="menuName">菜单编号</param>
    /// <param name="userId">用户ID</param>
    /// <param name="langId">多语</param>
    /// <returns></returns>
    [HttpPost, Route("ImportExcel")]
    public async Task<ServiceResult<QueryExportReturn>> ImportExcelAsync(IFormFile file, string menuName, int userId, int langId = 1)
    {
        return await _commonServices.ImportExcelAsync(file, menuName, langId, userId);
    }
    #endregion
}