<?php
namespace PortalPeopleStatis\modules\SatisfyManager\services;

class SatisService
{
    private string $satisFile;

    public function __construct(string $satisFile)
    {
        $this->satisFile = $satisFile;
    }

    public function getRepositories(): array
    {
        $data = json_decode(file_get_contents($this->satisFile), true);
        return $data['repositories'] ?? [];
    }

    public function addRepository(array $repo): void
    {
        $data = json_decode(file_get_contents($this->satisFile), true);
        $data['repositories'][] = $repo;
        file_put_contents($this->satisFile, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
    }

    public function updateRepository(int $index, array $repo): void
    {
        $data = json_decode(file_get_contents($this->satisFile), true);
        $data['repositories'][$index] = $repo;
        file_put_contents($this->satisFile, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
    }
}
