<commit_before><commit_msg>Add an event store usage example<commit_after><?php

require __DIR__ . '/../vendor/autoload.php';

use Ob\Hex\Domain\Email;
use Ob\Hex\Domain\MeetingRoom;
use Ob\Hex\Domain\Reservation;


// Create a meeting room with capacity for 10 people
$room = MeetingRoom::create(10, 180);


// Make a reservation at noon
$room->makeReservation(new Reservation(
    new DateTimeImmutable('today 12:00'),
    new DateTimeImmutable('today 13:00'),
    new Email('<EMAIL>')
));


// Plan a second reservation at 2 o'clock
$reservation = new Reservation(
    new DateTimeImmutable('today 14:00'),
    new DateTimeImmutable('today 16:15'),
    new Email('<EMAIL>')
);
// Invite 3 employees to the meeting
$reservation->invite(new Email('<EMAIL>'));
$reservation->invite(new Email('<EMAIL>'));
$reservation->invite(new Email('<EMAIL>'));
// Uninvite the last invitee
$reservation->uninvite(new Email('<EMAIL>'));
// Make the reservation
$room->makeReservation($reservation);


// Render the schedule
echo $room->renderScheduleWith(new \Ob\Hex\Application\PlainTextScheduleRenderer()) . PHP_EOL;


// Create an in-memory event store
$store = new \Ob\Hex\EventSourcing\Storage\MemoryStore();
// Persist the room schedule (the events)
$store->write(1, $room->getEvents());


// "Hydrate" the room from the event store
$storedRoom = MeetingRoom::createFromEvents($store->read(1));


// Render the schedule again, it should be identical
echo $room->renderScheduleWith(new \Ob\Hex\Application\PlainTextScheduleRenderer());
{'fraction_non_alphanumeric': 0.15072083879423329, 'fraction_numerical': 0.017693315858453473, 'mean_word_length': 5.157258064516129, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2325592', 'n_tokens_mistral': 496, 'n_tokens_neox': 462, 'n_words': 125}