<?php

declare(strict_types=1);

namespace Plugin\tnt_stabila_shop\src\Repositories;

use stdClass;

class ReportRepository extends \JTL\ServiceReport\ReportRepository
{
    /**
     * @return stdClass[]
     */
    public function getPluginReports(): array
    {
        return $this->getDB()->getObjects(
            'SELECT *
                FROM ' . $this->getTableName() . '
                WHERE file LIKE :filename
                ORDER BY id DESC',
            ['filename' => 'report_stabila_%'],
        );
    }

    public function reportAlreadyExists(string $reportName): bool
    {
        return $this->getDB()->getSingleObject(
            'SELECT *
                FROM ' . $this->getTableName() . '
                WHERE file LIKE :filename',
            ['filename' => 'report_stabila_' . $reportName . '_%'],
        ) === null;
    }
}
