<?php

namespace AsyncAws\Kinesis\Result;

use AsyncAws\Core\Response;
use AsyncAws\Core\Result;
use AsyncAws\Kinesis\ValueObject\Consumer;

class RegisterStreamConsumerOutput extends Result
{
    /**
     * An object that represents the details of the consumer you registered. When you register a consumer, it gets an ARN
     * that is generated by Kinesis Data Streams.
     *
     * @var Consumer
     */
    private $consumer;

    public function getConsumer(): Consumer
    {
        $this->initialize();

        return $this->consumer;
    }

    protected function populateResult(Response $response): void
    {
        $data = $response->toArray();

        $this->consumer = $this->populateResultConsumer($data['Consumer']);
    }

    private function populateResultConsumer(array $json): Consumer
    {
        return new Consumer([
            'ConsumerName' => (string) $json['ConsumerName'],
            'ConsumerARN' => (string) $json['ConsumerARN'],
            'ConsumerStatus' => (string) $json['ConsumerStatus'],
            'ConsumerCreationTimestamp' => /** @var \DateTimeImmutable $d */ $d = \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['ConsumerCreationTimestamp'])),
        ]);
    }
}
