<?php

namespace App\Platform\Tools\Request;

use App\Platform\Tools\HttpClient;
use GuzzleHttp\Client;
use Hyperf\Collection\LazyCollection;

class OrderRequest extends HttpClient
{

    const BATCH_SIZE = 50;

    public static function find(int $id): array
    {
        $path = "/api/ext/orders/$id";
        return static::get($path);
    }


    public static function findByPlatformOrderId(int $t_store_id, string $platform_order_id): array|bool
    {
        $path = "/api/ext/orders";
        $query = [
            'store' => $t_store_id,
            'platformOrderId' => $platform_order_id,
        ];
        $response = static::get($path, $query);

        if(isset($response['data']) && is_array($response['data']) && count($response['data']) == 1) {
            return $response['data']['0'];
        }

        return false;
    }

    public static function all(array $query):array
    {
        $path = "/api/ext/orders";
        return static::get($path, $query);
    }


    public static function add(array $data): array
    {
        $path = "/api/ext/orders";
        return static::post($path, [], $data);
    }

    public static function update(array $data): array
    {
        $path = "/api/ext/orders";
        return static::put($path, [], $data);
    }

    public static function queryByStorePlatformOrderIds(int $t_store_id, array $ids) : array
    {
      $path = "/api/ext/orders/batch-query-by-platform-order-ids";
      return static::post($path, [], ['store' => $t_store_id, 'platformOrderIds' => $ids]);
    }
}
