Files
actions-api/app/Services/Google/DTO/ImageGenerationResponse.php
Jurgis Sakalauskas 6df493fab3 initial commit
2025-01-08 12:45:00 +02:00

36 lines
1.1 KiB
PHP

<?php
namespace App\Services\Google\DTO;
use App\Services\Google\Error\APIError;
class ImageGenerationResponse
{
/**
* @var \App\Services\Google\DTO\ImageGenerationPrediction[]
*/
public readonly array $predictions;
public readonly ?APIError $error;
public function __construct(array $rawResponse)
{
if (isset($rawResponse['predictions']) && count($rawResponse['predictions']) > 0) {
$predictions = [];
foreach ($rawResponse['predictions'] as $prediction) {
$predictions[] = new ImageGenerationPrediction($prediction['bytesBase64Encoded'], $prediction['mimeType']);
}
$this->predictions = $predictions;
$this->error = null;
}
if (isset($rawResponse['error'])) {
$error = $rawResponse['error'];
$this->error = new APIError($error['message'], $error['code']);
}
if (!isset($this->predictions) && !isset($this->error)) {
$this->error = new APIError('An unknown error occurred.', 0,);
}
}
}