using EasyNetQ;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Collections.Generic;
using System.Threading.Tasks;
using XYY.Authentication.Standard;
using XYY.Common.Standard;
using XYY.Core.Standard.Mvc;
using XYY.Service.Standard.First.ESB;

namespace XYY.Api.First.Controllers
{ 
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ESBController : ControllerBase
    {
        IESBService eSBSendService;

        public ESBController(IESBService eSBSendService)
        {
            this.eSBSendService = eSBSendService;
        }

        public class Req
        {
            public List<TrackingDto> dtos { get; set; }
        }

         
        [HttpPost]
        public async Task<ApiJsonModel> Update(Req req)
        {
            var u = User.GetUserContent();
            await eSBSendService.Update(req.dtos, u.CustomerId);
            return ApiJsonModel.OK();
        }



        [AllowAnonymous]
        [HttpPost]
        public async Task<ApiJsonModel<PageResult<ZZESBTrackingApiInfo>>> QueryPager(QueryModel queueMode)
        {
            var pagers = await eSBSendService.GetPageResult(queueMode);
            return ApiJsonModel<PageResult<ZZESBTrackingApiInfo>>.OK(pagers);
        }

        [AllowAnonymous]
        [HttpPost]
        public async Task<ApiJsonModel> Retry(ESBKeyList list)
        {
            await eSBSendService.Retry(list.Keys);
            return ApiJsonModel.OK();
        }
    }
}
