
using BPA.KitChen.GroupMeal.Application.BaseDto;
using BPA.KitChen.GroupMeal.Application.Service.Authorization.Dtos;
using BPA.KitChen.GroupMeal.Core.Entity;
using Furion.DatabaseAccessor;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.KitChen.GroupMeal.Application.Service.Authorization
{

    [ApiDescriptionSettings("授权管理", Tag = "授权管理")]
    public class AuthorizationServices: IDynamicApiController
    {
        private readonly Services.IAuthorizationService _authorizationService;
        public AuthorizationServices(Services.IAuthorizationService authorizationService)
        {
            _authorizationService = authorizationService;
        }

        
        /// <summary>
        /// 分页店铺授权码
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("/api/authorization/pagestoreauthorization")]
        public async Task<PageUtil> PageStoreAuthorization(PageInputBase input)
        {
            return await _authorizationService.PageStoreAuthorization(input);
        }

        /// <summary>
        /// 添加店铺授权码
        /// </summary>
        /// <returns></returns>
        [HttpPost("/api/authorization/addstoreauthorization")]
        public async Task<bool> AddStoreAuthorization(CreateOrUpDateStoreAuthorizationDto input)
        {
            return await _authorizationService.AddStoreAuthorization(input);
        }

        /// <summary>
        /// 修改店铺授权码
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost("/api/authorization/updatestoreauthorization")]
        public async Task<bool> UpdateStoreAuthorization(string id)
        {
            return await _authorizationService.UpdateStoreAuthorization(id);
        }

        /// <summary>
        /// 修改店铺授权时间
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("/api/authorization/updatestoreauthtime")]
        public async Task<bool> UpdateStoreAuthTime(CreateOrUpDateStoreAuthorizationDto input)
        {
            return await _authorizationService.UpdateStoreAuthTime(input);
        }

        /// <summary>
        /// 删除店铺权限
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost("/api/authorization/delstoreauthorization")]
        public async Task<bool> DelStoreAuthorization(string id)
        {
            return await _authorizationService.DelStoreAuthorization(id);
        }


        /// <summary>
        /// 查询店铺授权信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("/api/authorization/GetStoreAuthorizationById")]
        public async Task<BPA_StoreAuthorization> GetStoreAuthorizationById(string id)
        {
            return await _authorizationService.GetStoreAuthorizationById(id);
        }

        /// <summary>
        /// 查询店铺授权信息 更具KEY
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet("/api/authorization/GetStoreAuthorizationByKey"), AllowAnonymous]
        public async Task<BPA_StoreAuthorization> GetStoreAuthorizationByKey(string key)
        {
            return await _authorizationService.GetStoreAuthorizationByKey(key);
        }

        /// <summary>
        /// CodeFirst
        /// </summary>
        /// <param name="tableNames"></param>
        public void CodeFirst()
        {
            _authorizationService.CodeFirst();
        }
    }
}
