using Furion.DynamicApiController;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Nirvana.Common;
using Nirvana.Common.ApiBase;
using System;
using System.Threading.Tasks;
using YBDevice.Entity;

namespace YBDevice.Application.OfficeialInfo
{
    /// <summary>
    /// 公众号管理
    /// </summary>
    [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
    public class OfficialAppService : IDynamicApiController
    {
        private readonly IOfficialService _Service;
        public OfficialAppService(IOfficialService Service)
        {
            _Service = Service;
        }
        /// <summary>
        /// 更新公众号/小程序资料
        /// </summary>
        /// <param name="id">公众号ID</param>
        /// <returns></returns>
        [QueryParameters]
        public async Task<ResultInfo> GetInfo(int id)
        {
            return await _Service.GetInfo(id);
        }
        /// <summary>
        /// 公众号列表
        /// </summary>
        /// <param name="param"></param>
        /// <param name="type">0-全部,1-公众号,2-小程序</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> GetListAsync(QueryParams param, [FromQuery] int type = 1)
        {
            var result = await _Service.GetListAsync(param, type);
            return new ResultInfo(ResultState.SUCCESS, "success", result);
        }

        /// <summary>
        /// 获取所有公众号列表
        /// </summary>
        /// <param name="type">0-全部,1-公众号,2-小程序</param>
        /// <returns></returns>
        [HttpGet]
        [QueryParameters]
        public async Task<ResultInfo> GetAllListAsync(int type = 1)
        {
            var data = await _Service.GetAllListAsync(type);
            return new ResultInfo(ResultState.SUCCESS, "success", data);
        }
        /// <summary>
        /// 小程序模版列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> GetTplListAsync(QueryParams param)
        {
            var result = await _Service.GetTplListAsync(param);
            return new ResultInfo(ResultState.SUCCESS, "success", result);
        }
        /// <summary>
        /// 获取小程序草稿列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> GetDraftListAsync(QueryParams param)
        {
            var result = await _Service.GetDraftListAsync(param);
            return new ResultInfo(ResultState.SUCCESS, "success", result);
        }
        /// <summary>
        /// 同步代码模版列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultInfo> SyncTplAsync()
        {
            var result = await _Service.SyncTplAsync();
            return result;
        }
        /// <summary>
        /// 同步代码草稿列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultInfo> SyncDraftAsync()
        {
            var result = await _Service.SyncDraftAsync();
            return result;
        }


        /// <summary>
        /// 将草稿箱的草稿选为小程序代码模版
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [QueryParameters]
        public async Task<ResultInfo> AddToTemplateAsync(int id)
        {
            var result = await _Service.AddToTEmplateAsync(id);
            return result;
        }
        /// <summary>
        /// 删除模版
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [QueryParameters]
        public async Task<ResultInfo> DeleteTemplateAsync(int id)
        {
            var result = await _Service.DeleteTemplateAsync(id);
            return result;
        }

        /// <summary>
        /// 获取小程序的体验二维码
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [QueryParameters]
        public async Task<ResultInfo> GetQRCodeAsync(int id)
        {
            var result = await _Service.GetQRCodeAsync(id);
            return result;
        }

        /// <summary>
        /// 为授权的小程序帐号上传小程序代码
        /// </summary>
        /// <param name="templateid"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [QueryParameters]
        public async Task<ResultInfo> CommitAsync(int templateid, int id)
        {
            var result = await _Service.CommitAsync(templateid, id);
            return result;
        }
        /// <summary>
        /// 提交审核
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [QueryParameters]
        public async Task<ResultInfo> SubmitAuditAsync(int id)
        {
            var result = await _Service.SubmitAuditAsync(id);
            return result;
        }
        /// <summary>
        /// 发布版本
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [QueryParameters]
        public async Task<ResultInfo> ReleaseAsync(int id)
        {
            var result = await _Service.ReleaseAsync(id);
            return result;
        }
        /// <summary>
        /// 获取最新的审核状态
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [QueryParameters]
        public async Task<ResultInfo> GetLatestAuditStatusAsync(int id)
        {
            var result = await _Service.GetLatestAuditStatusAsync(id);
            return result;
        }
        /// <summary>
        /// 查询提交状态
        /// </summary>
        /// <param name="id">提交的状态记录id</param>
        /// <returns></returns>
        [QueryParameters]
        public async Task<ResultInfo> GetCommitStatusAsync(int id)
        {
            var result = await _Service.GetCommitStatusAsync(id);
            return result;
        }
        /// <summary>
        /// 修改域名
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [QueryParameters]
        public async Task<ResultInfo> ModifyDomainAsync(int id)
        {
            var result = await _Service.ModifyDomainAsync(id);
            return result;
        }
        /// <summary>
        /// 获取域名列表
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [QueryParameters]
        public async Task<ResultInfo> GetDomainAsync(int id)
        {
            var result = await _Service.GetDomainAsync(id);
            return result;
        }

        /// <summary>
        /// 获取提交历史列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> GetHistoryListAsync(QueryParams param)
        {
            var result = await _Service.GetHistoryListAsync(param);
            return new ResultInfo(ResultState.SUCCESS, "success", result);
        }

        /// <summary>
        /// 小程序审核撤回，注意：单个帐号每天审核撤回次数最多不超过 1 次，一个月不超过 10 次
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [QueryParameters]
        public async Task<ResultInfo> UndoCodeAuditAsync(int id)
        {
            return await _Service.UndoCodeAuditAsync(id);
        }

        /// <summary>
        /// 手动增加公众号/小程序
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public async Task<ResultInfo> SubmitFormAsync(YB_OfficlaAccount data)
        {
            return await _Service.SubmitFormAsync(data);
        }
        /// <summary>
        /// 获取小程序订阅模板
        /// </summary>
        /// <param name="param"></param>
        /// <param name="id">小程序id</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> GetSubscribeTplListAsync([FromQuery] int id, QueryParams param)
        {
            return await _Service.GetSubscribeTplListAsync(id, param);
        }
        /// <summary>
        /// 获取当前账号下的个人模板列表
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [QueryParameters]
        public async Task<ResultInfo> GetTemplateListAsync(int id)
        {
            return await _Service.GetTemplateListAsync(id);
        }

        /// <summary>
        /// 选中模板
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public async Task<ResultInfo> SetTplAsMessageAsync(SubscribeTplStatusC2SDto data)
        {
            return await _Service.SetTplAsMessageAsync(data);
        }
        /// <summary>
        /// 设置订阅消息模板内容
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> SetSubscribeTplContentAsync(SubscribeTplContentC2SDto data)
        {
            return await _Service.SetSubscribeTplContentAsync(data);
        }
        /// <summary>
        /// 微信客服设置
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public async Task<ResultInfo> SetCustomServiceAsync(CustomServiceC2SDto data)
        {
            return await _Service.SetCustomServiceAsync(data);
        }
    }
}
