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.OrderInfo
{
    /// <summary>
    /// 订单管理
    /// </summary>
    [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
    public class OrderAppService : IDynamicApiController
    {
        private readonly IOrderService _orderService;
        public OrderAppService(IOrderService orderService)
        {
            _orderService = orderService;
        }

        /// <summary>
        /// 订单列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> GetListAsync(QueryParams param)
        {
            var result = await _orderService.GetListAsync(param);
            return new ResultInfo(ResultState.SUCCESS, "success", result);
        }

        /// <summary>
        /// 状态变更
        /// </summary>
        /// <param name="id"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        [HttpGet]
        [QueryParameters]
        public async Task<ResultInfo> SetStatusAsync(Guid id, OrderStatus status)
        {
            return await _orderService.SetStatusAsync(id, status);
        }

        /// <summary>
        /// 信息提交
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<ResultInfo> SubmitAsync(OrderSubmitDto model)
        {
            return await _orderService.SubmitAsync(model);
        }

        /// <summary>
        /// 获取订单设备列表
        /// </summary>
        /// <param name="orderid"></param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <param name="code">设备序列号</param>
        /// <param name="type">设备类型</param>
        /// <returns></returns>
        [QueryParameters]
        public async Task<ResultInfo> GetOrderEquListAsync(Guid orderid,int type=0, int page = 1, int pagesize = 50, string code = "")
        {
            var data= await _orderService.GetOrderEquListAsync(orderid, page, pagesize, code,type);
            return new ResultInfo(ResultState.SUCCESS, "success", data);
        }
    }
}
