<?php

namespace App\Http\Controllers;

use App\Helpers\MiscHelper;
use App\Models\Catalog;
use App\Models\Company;
use App\Models\CompanyLocation;
use App\Models\Customer;
use App\Models\Order;
use App\Models\Product;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use App\Models\Variant;
use App\Services\Navision\ContactsService;
use App\Services\Navision\LicensesService;
use App\Services\Navision\OrdersService as NavisionOrdersService;
use App\Services\Navision\ProductsService;
use App\Services\Shopify\CustomersService;
use App\Services\Shopify\LicensesService as ShopifyLicensesService;
use App\Services\Shopify\OrdersService;
use App\Services\Shopify\ProductsService as ShopifyProductsService;
use Carbon\Carbon;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public function test(Request $request, ShopifyLicensesService $shopLicensesService, LicensesService $licensesService, NavisionOrdersService $navOrdersService, OrdersService $ordersService, ProductsService $service, ShopifyProductsService $shopifyService, ContactsService $contactsService, CustomersService $customerService)
    {
        //return $service->getAndSyncItem('BOM-XCAM-TEST', true);
        //$shopifyService->syncProduct(Product::first());
        //$service->getAndSyncItems(true, false);
        //$service->getAndSyncOptions();

        //$service->getAndSyncItem('XAPS-12V1', true);

        //$shopifyService->syncProduct(Product::where('nav_no', 'DVTD-0010')->first());
        //$shopifyService->syncProduct(Product::where('nav_no', 'BOM-XCAM-TEST')->first());
        //$shopifyService->syncProduct(Product::where('nav_no', 'XAPS-12V1')->first());
        //$shopifyService->syncProduct(Product::where('nav_no', 'DVDL-TCN-150200')->first());

        //$shopifyService->syncProduct(Product::where('nav_no', 'XCMB-DUAL-3IN')->first());
        //$shopifyService->syncCollections();
        //$shopifyService->syncCatalog(Catalog::find(1));
        //$shopifyService->syncCatalogs();
        //$shopifyService->test();

        //SyncProduct::dispatch(2);
        $contactsService->getAndSyncCompany('C12801');
        //$contactsService->countCompanies();
        //$contactsService->countContacts();
        //$customerService->syncCompany(Company::find(30197));
        //$customerService->syncCustomer(Customer::find(22009));
        //$customerService->syncCustomer(Customer::find(22010));
        //$customerService->syncCustomer(Customer::find(25131));

        //$customerService->syncCompanyCatalogs(Company::find(1));
        //$contactsService->getAndSyncContacts();
        //$contactsService->getAndSyncContact('CTU46869');


        //$ordersService->addOrderTag(Order::first(), 'test');

        //$navOrdersService->createNavOrder(Order::find(17));

        //$shopifyService->syncVariantPrice(Variant::find(1));

        //$contactsService->countCompanies();
        //$service->getAndSyncPrices();
        //dd(Carbon::now());

        //$licensesService->getCompanyLicenses(Company::find(1));
        //$shopLicensesService->cleanLicenseProducts();

        //$customerService->test();
/*
        $token = substr($request->header('Authorization'), 7);
        echo $token;

        $decoded = JWT::decode($token, new Key(config('shopify-app.api_secret'), 'HS256'));
var_dump($decoded);
*/
        return '1';
    }
}
