<?php

namespace Modules\Additional\Specifique\Client160\Modules\Fournisseur\Service;

use Modules\Additional\Specifique\Client160\Modules\Fournisseur\Repository\QualityReview;
use Zend\Stdlib\ArrayStack;

class QualityReviewService
{
    private \PDO $pdo;
    private QualityReview $repository;

    public function __construct(\PDO $pdo)
    {
        $this->pdo = $pdo;
        $this->repository = new QualityReview($this->pdo);
    }
    
    /**
     * getListNonConf
     *
     * @param  array<mixed> $post
     * @return array<mixed>|false
     */
    public function getListNonConf(array $post = [])
    {
        $headingList = $this->repository->getListNonConfHeading($post);
        $linesList = $this->repository->getListNonConfLines();

        // on trie le tableau des entêtes en mettant l'index unique en index du tableau
        $sortedHeadingList = [];
        foreach ((array)$linesList as $line) {
            $sortedHeadingList[$line['ZQMNUM']]['lines'][] = $line;
        }

        foreach ((array)$headingList as &$value) {
            $value['lines'] = $sortedHeadingList[$value['ZQMNUM']]['lines'];
        }

        return $headingList;
    }
}
