<?php

namespace Modules\GlobalApplication\Repository;

use Helpers\QueryBuilder\AbsRepository;

class JournalExportRepo extends AbsRepository
{
    /**
     * @param array<mixed> $post
     * @return \PDOStatement
     */
    public function listEvent(\DateTime $dateLimit, array $post)
    {
        $req = <<<EOT
            SELECT *
            FROM XT_EVE with(nolock)
            WHERE CONCAT(DATEEVT, HEUREEVT) > :dateLimit
                AND CONCAT(DATEEVT, HEUREEVT) = (
                SELECT MAX(CONCAT(DATEEVT, HEUREEVT))
                FROM XT_EVE as lastEve
                WHERE XT_EVE.TYPEOBJ = lastEve.TYPEOBJ
                    AND XT_EVE.ID_1 = lastEve.ID_1
                    AND XT_EVE.ID_2 = lastEve.ID_2
                    AND XT_EVE.ID_3 = lastEve.ID_3
                    AND XT_EVE.ID_4 = lastEve.ID_4
                    AND XT_EVE.ID_5 = lastEve.ID_5
            )
        EOT;
        $param = [
            'dateLimit' => $dateLimit->format('YmdHis'),
        ];

        $req = $this->applyFilter($req, $param, $post);

        return $this->createStatement($req, $param);
    }
}
