using Knoks.Api.Client;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;

namespace Knoks.Api.Client.Invoker
{
    public static class ApiInvoker
    {
        public static async Task<ApiResult<User>> InvokeCreateUser(this ApiClient apiClient, CreateUserArgs args)
        {
            return await apiClient.Request<User>($"General/NewUser", args);
        }

        public static async Task<ApiResult<TokenResponse>> InvokeSignInUser(this ApiClient apiClient, string username, string password)
        {
            return await apiClient.AuthorizeApiUser(username, password);
        }

        //public static async Task<ApiResult<UserAccounts>> InvokeGetUserAccounts(this ApiClient apiClient)
        //{
        //    return await apiClient.Request<UserAccounts>($"Account/UserAccounts");
        //}

        public static async Task<ApiResult<Operator>> InvokeCreateOperator(this ApiClient apiClient, CreateOperatorArgs args)
        {
            return await apiClient.Request<Operator>("General/Operator", args);
        }

        public static async Task<ApiResult<AccountTransaction>> InvokeFreeTokensCreditTransaction(this ApiClient apiClient, AddAccountTransactionArgs args)
        {
            return await apiClient.Request<AccountTransaction>("BackOffice/FreeTokensCredit", args);
        }

        public static async Task<ApiResult<AccountTransaction>> InvokeDeposit(this ApiClient apiClient, AddAccountTransactionArgs args)
        {
            return await apiClient.Request<AccountTransaction>("BackOffice/Deposit", args);
        }
        
        public static async Task<ApiResult<AccountTransaction>> InvokeWithdraw(this ApiClient apiClient, AddAccountTransactionArgs args)
        {
            return await apiClient.Request<AccountTransaction>("BackOffice/Withdraw", args);
        }
        
        public static async Task<ApiResult<AccountTransaction>> InvokePublishKnok(this ApiClient apiClient, AddAccountTransactionArgs args)
        {
            return await apiClient.Request<AccountTransaction>("BackOffice/PublishKnok", args);
        }
        
        public static async Task<ApiResult<AccountTransaction>> InvokeKnokerWinsToken(this ApiClient apiClient, AddAccountTransactionArgs args)
        {
            return await apiClient.Request<AccountTransaction>("BackOffice/KnokerWinsToken", args);
        }
        
        public static async Task<ApiResult<AccountTransaction>> InvokePlatformWinsToken(this ApiClient apiClient, AddAccountTransactionArgs args)
        {
            return await apiClient.Request<AccountTransaction>("BackOffice/PlatformWinsToken", args);
        }
        
        public static async Task<ApiResult<AccountTransaction>> InvokeUserBuyExposure(this ApiClient apiClient, AddAccountTransactionArgs args)
        {
            return await apiClient.Request<AccountTransaction>("BackOffice/UserBuyExposure", args);
        }
        
        public static async Task<ApiResult<AccountTransaction>> InvokeUserBuyKnok(this ApiClient apiClient, AddAccountTransactionArgs args)
        {
            return await apiClient.Request<AccountTransaction>("BackOffice/UserBuyKnok", args);
        }
        
        public static async Task<ApiResult<AccountTransaction>> InvokeUserRefundToken(this ApiClient apiClient, AddAccountTransactionArgs args)
        {
            return await apiClient.Request<AccountTransaction>("BackOffice/UserRefundToken", args);
        }
        
        public static async Task<ApiResult<AccountTransaction>> InvokeUserBuySideBet(this ApiClient apiClient, AddAccountTransactionArgs args)
        {
            return await apiClient.Request<AccountTransaction>("BackOffice/UserBuySideBet", args);
        }
        
        public static async Task<ApiResult<AccountTransaction>> InvokeUserWinsSideBet(this ApiClient apiClient, AddAccountTransactionArgs args)
        {
            return await apiClient.Request<AccountTransaction>("BackOffice/UserWinsSideBet", args);
        }
        
        public static async Task<ApiResult<AccountTransaction>> InvokePlatformLooseSideBet(this ApiClient apiClient, AddAccountTransactionArgs args)
        {
            return await apiClient.Request<AccountTransaction>("BackOffice/PlatformLooseSideBet", args);
        }
        
        public static async Task<ApiResult<AccountTransaction>> InvokeUserReceiveToken(this ApiClient apiClient, AddAccountTransactionArgs args)
        {
            return await apiClient.Request<AccountTransaction>("BackOffice/UserReceiveToken", args);
        }
        
        public static async Task<ApiResult<AccountTransaction>> InvokeUserUpgradeToGold(this ApiClient apiClient, AddAccountTransactionArgs args)
        {
            return await apiClient.Request<AccountTransaction>("BackOffice/UserUpgradeToGold", args);
        }
        
        public static async Task<ApiResult<AccountTransaction>> InvokeAffiliateCommision(this ApiClient apiClient, AddAccountTransactionArgs args)
        {
            return await apiClient.Request<AccountTransaction>("BackOffice/AffiliateCommision", args);
        }
        
        public static async Task<ApiResult<AccountTransaction>> InvokeFreeTokensReturn(this ApiClient apiClient, AddAccountTransactionArgs args)
        {
            return await apiClient.Request<AccountTransaction>("BackOffice/FreeTokensReturn", args);
        }
        
        //public static async Task<ApiResult<TokenResponse>> InvokeSignInOperator(this ApiClient apiClient, string operatorName, string operatorPassword)
        //{
        //    return await apiClient.AuthorizeApiOperate(operatorName, operatorPassword);
        //}

    public static async Task<ApiResult<UserAccounts>> InvokeUserAccounts(this ApiClient apiClient)
        {
            return await apiClient.Request<UserAccounts>("Account/UserAccounts");
        }

        public static async Task<ApiResult<ApiArray<Country>>> InvokeCountries(this ApiClient apiClient, string countryCode2 = null)
        {
            return await apiClient.Request<ApiArray<Country>>($"General/Countries/{countryCode2}");
        }

        
        public static async Task<ApiResult<TokenResponse>> InvokeTokenRefresh(this ApiClient apiClient)
        {
            return await apiClient.Request<TokenResponse>("Token/Refresh");
        }

        public static async Task<ApiResult<ApiObject<bool>>> InvokeTokenHeartbit(this ApiClient apiClient)
        {
            return await apiClient.Request<ApiObject<bool>>("Token/Heartbit");
        }
    }
}
