<?php

namespace App\Platform\Tools\Request;

use App\Platform\Tools\HttpClient;

// @attention Tools 暂未提供 platform 接口

class PlatformRequest extends HttpClient
{

    public static function one(string $id): array
    {
        return parent::get("api/ext/platforms/$id");
    }
    
    public static function find(string $name)
    {

        $platforms = self::all();
        $platforms = $platforms->filter(function($el) use ($name){
            return strtolower($el['label']) == $name ? $el : null;
        });

        if($platforms->isEmpty()){
            throw new \InvalidArgumentException("tools 中未找到 name 为 $name 的公司信息，请确认 tools 系统中已创建该公司的记录！");
        }

        return $platforms->first();
    }
    public static function all($query = []): array
    {
        $path = 'api/ext/platforms';
        return static::fetch($collection, $path, $query);
    
    }

    protected static function fetch($path, $query)
    {
       return static::get($path, $query);
    }

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




}
