<?php

namespace App\Modules\Package\Application\GetCampSchedule;

class DataGroup
{
    private $dataMap;
    public function __construct(
        public array $data,
        public string $key
    ) {
        $this->generate();
    }

    private function generate()
    {
        $this->dataMap = collect($this->data)->groupBy($this->key)->toArray();
    }

    public function getObject(string $key)
    {
        return isset($this->dataMap[$key]) ? $this->dataMap[$key][0] : null;
    }
}
