<?php

namespace Modules\PrintSuppliers\Controllers;

use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Modules\PrintSuppliers\Models\PrintLogisticSku;
use Illuminate\Support\Facades\Config;
use Modules\PrintSuppliers\Models\Order;
use Modules\PrintSuppliers\Models\Shipper;
use Modules\PrintSuppliers\Models\OrderMeta;
use Carbon\Carbon;
use Modules\PrintSuppliers\Models\OrderItem;
// use GuzzleHttp\Client;

class ProLuxuryController extends Controller
{
    private $apiUrl;
    private $credential;

    public function __construct()
    {
        $this->credential = $this->getCredential('printerval', 'proluxury');
        $this->apiUrl = Config::get('print-suppliers::connection.proluxry.api_url', 'http://bops.xiaosache.com/zspic');
    }

    public function internalCallApi(Request $request)
    {
        $endPoint = $request->input('end_point');
        $method = $request->input('method', 'GET');
        $params = $request->input('params', []);
        
        return $this->triggerSyncRequest($this->apiUrl . '/' . $endPoint, $method, $params, [
            'x-api-key: ' . $this->credential[1],
            'Content-Type: application/json'
        ]);
    }

    public function getProducts()
    {
        $products = DB::table('proluxury_products')->groupBy('product_name')->get();

        return $products;
    }

    public function getSkus(Request $request)
    {
        $productName = $request->input('product_name');

        $skus = DB::table('proluxury_products')->where('product_name', $productName)->get();

        return $skus;
    }
}
