<?php

namespace Modules\Stock\Service\Validation;

use Exception;
use Helpers\Trad\ITrad;
use Modules\Stock\Trait\ValidationErrorTrait;
use PDO;

abstract class AbstractEnteteValidationService
{
    use ValidationErrorTrait;

    /**
     * @var array<int,array<string,mixed>>
     */
    protected array $errors = [];

    /**
     * @var array<int,array<string,mixed>>
     */
    protected array $bloquantErrors = [];

    /**
     * @var array<int,array<string,mixed>>
     */
    protected array $nonBloquantErrors = [];

    /**
     * @var bool
     */
    protected bool $isValid = true;

    /**
     * @var PDO
     */
    protected PDO $pdo;

    protected ITrad $trad;

    /**
     * @param array<string,mixed> $enteteEntity
     * @param array<int,array<string,mixed>> $ligneEntities
     * @return $this
     * @throws Exception
     */
    abstract public function validate(array $enteteEntity, array $ligneEntities): self;


    /**
     * @return array<int,array<string,mixed>>
     */
    public function getErrors(): array
    {
        return $this->errors;
    }

    public function isNonBloquant(): bool
    {
        return count($this->bloquantErrors) === 0 && count($this->nonBloquantErrors) > 0;
    }

    public function isValid(): bool
    {
        return $this->isValid;
    }
}
