<?php

namespace Helpers\Log;

class OxaEventDet
{
    private \PDO $pdo;
    protected string $etat = 'O';
    private \Entity\Model\OxaEventDet $event;
    private string $numeroTraitement;
    
    public function __construct(\PDO $pdo, string $numeroTraitement = '')
    {
        $this->pdo = $pdo;
        $this->event = new \Entity\Model\OxaEventDet($this->pdo);
        $this->numeroTraitement = $numeroTraitement;
    }
    
    public function setLog(string $etat, string $description = '', string $descLong = '') :void
    {
        $this->event->insert([
            'NUMTRT' => $this->numeroTraitement,
            'DATEEVT' => date('Ymd'),
            'HEUREEVT' => date('His'),
            'RESULTEVT' => $etat,
            'LIBCOURT' => substr($description, 0, 200),
            'LIBSUPERLONG' => substr($descLong, 0, 3000),
        ]);

        if ($this->etat == 'O') {
            $this->etat = $etat;
        }
    }
    public function getEtat() :string
    {
        return $this->etat;
    }
}
