<?php

namespace App\Service;

use JetBrains\PhpStorm\ArrayShape;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

class LastRelease
{
    #[ArrayShape([
        "branch" => "string",
        "date" => "string",
        "commitHashShort" => "string",
        "commitHashLong" => "string",
        "commitDate" => "string",
        "branchUrl" => "string",
        "projectUrl" => "string",
        "commitUrl" => "string",
    ])]
    private array $lastRelease = [];

    public function __construct(#[Autowire('%kernel.project_dir%/release.json')] string $jsonFile)
    {
        if (file_exists($jsonFile)) {
            $this->lastRelease = json_decode(file_get_contents($jsonFile), true);
        }
    }

    public function getBranch(): string
    {
        return $this->lastRelease['branch'] ?? '-';
    }

    public function getBranchUrl(): string
    {
        return $this->lastRelease['branchUrl'] ?? '#';
    }

    public function getProjectUrl(): string
    {
        return $this->lastRelease['projectUrl'] ?? '#';
    }

    public function getCommitUrl(): string
    {
        return $this->lastRelease['commitUrl'] ?? '#';
    }

    public function getDate(): string
    {
        return $this->lastRelease['date'] ?? '-';
    }

    public function getCommitHashShort(): string
    {
        return $this->lastRelease['commitHashShort'] ?? '-';
    }

    public function getCommitHashLong(): string
    {
        return $this->lastRelease['commitHashLong'] ?? '-';
    }

    public function getCommitDate(): string
    {
        return $this->lastRelease['commitDate'] ?? '-';
    }

}