using Knoks.Api.Controllers.Base;
using Knoks.Api.Entities;
using Knoks.Core.Data.Interfaces;
using Knoks.Core.Entities;
using Knoks.Core.Entities.Args;
using Knoks.Core.Logic.Interfaces;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;

namespace Knoks.Api.Controllers
{
    [Route("v1/[controller]")]
    public class BackofficeController : UserController
    {
        private readonly IBackofficeManager _backofficeManager;
        private readonly IUserManager _userManager;
        
        public BackofficeController(
            IBackofficeManager backofficeManager,
            IUserManager userManager)
        {
            _backofficeManager = backofficeManager;
            _userManager = userManager;
        }

        [HttpGet("users")]
        public async Task<ApiArray<User>> GetUsers([FromQuery]long? u = null)
        {
            return new ApiArray<User>(await _userManager.GetUsers(u));
        }

        [HttpPost("FreeTokensCredit")]
        public async Task<AccountTransaction> FreeTokensCredit([FromBody]AddAccountTransactionArgs args)
        {
            return await _backofficeManager.FreeTokensCredit(args);
        }

        [HttpPost("Deposit")]
        public async Task<AccountTransaction> Deposit([FromBody]AddAccountTransactionArgs args)
        {
            return await _backofficeManager.Deposit(args);
        }

        [HttpPost("Withdraw")]
        public async Task<AccountTransaction> Withdraw([FromBody]AddAccountTransactionArgs args)
        {
            return await _backofficeManager.Withdraw(args);
        }

        [HttpPost("PublishKnok")]
        public async Task<AccountTransaction> PublishKnok([FromBody]AddAccountTransactionArgs args)
        {
            return await _backofficeManager.PublishKnok(args);
        }
        
        [HttpPost("KnokerWinsToken")]
        public async Task<AccountTransaction> KnokerWinsToken([FromBody]AddAccountTransactionArgs args)
        {
            return await _backofficeManager.KnokerWinsToken(args);
        }
        
        [HttpPost("PlatformWinsToken")]
        public async Task<AccountTransaction> PlatformWinsToken([FromBody]AddAccountTransactionArgs args)
        {
            return await _backofficeManager.PlatformWinsToken(args);
        }
        
        [HttpPost("UserBuyExposure")]
        public async Task<AccountTransaction> UserBuyExposure([FromBody]AddAccountTransactionArgs args)
        {
            return await _backofficeManager.UserBuyExposure(args);
        }
        
        [HttpPost("UserBuyKnok")]
        public async Task<AccountTransaction> UserBuyKnok([FromBody]AddAccountTransactionArgs args)
        {
            return await _backofficeManager.UserBuyKnok(args);
        }
        
        [HttpPost("UserRefundToken")]
        public async Task<AccountTransaction> UserRefundToken([FromBody]AddAccountTransactionArgs args)
        {
            return await _backofficeManager.UserRefundToken(args);
        }
        
        [HttpPost("UserBuySideBet")]
        public async Task<AccountTransaction> UserBuySideBet([FromBody]AddAccountTransactionArgs args)
        {
            return await _backofficeManager.UserBuySideBet(args);
        }
        
        [HttpPost("UserWinsSideBet")]
        public async Task<AccountTransaction> UserWinsSideBet([FromBody]AddAccountTransactionArgs args)
        {
            return await _backofficeManager.UserWinsSideBet(args);
        }
        
        [HttpPost("PlatformLooseSideBet")]
        public async Task<AccountTransaction> PlatformLooseSideBet([FromBody]AddAccountTransactionArgs args)
        {
            return await _backofficeManager.PlatformLooseSideBet(args);
        }
        
        [HttpPost("UserReceiveToken")]
        public async Task<AccountTransaction> UserReceiveToken([FromBody]AddAccountTransactionArgs args)
        {
            return await _backofficeManager.UserReceiveToken(args);
        }
        
        [HttpPost("UserUpgradeToGold")]
        public async Task<AccountTransaction> UserUpgradeToGold([FromBody]AddAccountTransactionArgs args)
        {
            return await _backofficeManager.UserUpgradeToGold(args);
        }
        
        [HttpPost("AffiliateCommision")]
        public async Task<AccountTransaction> AffiliateCommision([FromBody]AddAccountTransactionArgs args)
        {
            return await _backofficeManager.AffiliateCommision(args);
        }
        
        [HttpPost("FreeTokensReturn")]
        public async Task<AccountTransaction> FreeTokensReturn([FromBody]AddAccountTransactionArgs args)
        {
            return await _backofficeManager.FreeTokensReturn(args);
        }
        

        //[HttpGet("LoanRequests/{pageSize}/{pageNumber}")]
        //public async Task<BoLoanRequestsResult> LoanRequests([FromRoute]int pageSize, [FromRoute]int pageNumber, [FromQuery]LoanRequestStatusTypes? loanRequestStatusType = null, [FromQuery]long? loanRequestId = null, [FromQuery]long? userId = null)
        //{
        //    return await _backofficeManager.LoadBoLoanRequests(new GetBoLoanRequestsArgs()
        //    {
        //        OperatorId = ContextOperatorId.Value,
        //        PageNumber = pageNumber,
        //        PageSize = pageSize,
        //        LoanRequestStatusTypeId = loanRequestStatusType,
        //        UserId = userId,
        //        LoanRequestId = loanRequestId,
        //    });
        //}
        //[HttpGet("LoanRequests/Count")]
        //public async Task<BoLoanRequestsCountsResult> LoanRequestsCount([FromQuery]bool? isActive = false)
        //{
        //    return await _backofficeManager.LoadBoLoanRequestsCount(new GetBoLoanRequestsCountArgs()
        //    {
        //        OperatorId = ContextOperatorId.Value,
        //        IsActive = isActive
        //    });
        //}

    //[HttpGet("Loans/{pageSize}/{pageNumber}")]
    //public async Task<BoLoansResult> Loans([FromRoute]int pageSize, [FromRoute]int pageNumber, [FromQuery]LoanStatus? loanStatus = null, [FromQuery]long? loanId = null, [FromQuery]long? userId = null)
    //{
    //    return await _backofficeManager.LoadBoLoans(new GetBoLoansArgs
    //    {
    //        OperatorId = ContextOperatorId.Value,
    //        PageNumber = pageNumber,
    //        PageSize = pageSize,
    //        LoanStatusId = loanStatus,
    //        UserId = userId,
    //        LoanId = loanId,
    //    });
    //}

    //[HttpGet("Loans/Count")]
    //public async Task<BoLoansCountResult> LoansCount()
    //{
    //    return await _backofficeManager.LoadBoLoansCount(new GetBoLoansCountArgs()
    //    {
    //        OperatorId = ContextOperatorId.Value
    //    });
    //}

    //[HttpGet("VerificationFilePreview/{userId}/{loanRequestId}/{propertyId}/{fileName}")]
    //public FileStreamResult PreviewVerificationFile([FromRoute]long userId, [FromRoute]long loanRequestId, [FromRoute]LoanRequestProperty propertyId, [FromRoute]string fileName)
    //{
    //    return File(_documentManager.LoadVerification(userId, loanRequestId, propertyId, fileName), "image/png");
    //}

    //[HttpGet("VerificationFileDownload/{userId}/{loanRequestId}/{propertyId}/{fileName}")]
    //public FileResult DownloadVerificationFile([FromRoute]long userId, [FromRoute]long loanRequestId, [FromRoute]LoanRequestProperty propertyId, [FromRoute]string fileName)
    //{
    //    var result = File(_documentManager.LoadVerificationBytes(userId, loanRequestId, propertyId, fileName), "image/jpeg");
    //    result.FileDownloadName = fileName;
    //    return result;
    //}
    //[HttpGet("Menu/Counts")]
    //public async Task<BoMenuCountsResult> MenuCounts()
    //{
    //    return await _backofficeManager.LoadBoMenuCounts(new GetBoMenuCountsArgs()
    //    {
    //        OperatorId = ContextOperatorId.Value
    //    });
    //}
}
}
