<?php

namespace Modules\Additional\Specifique\Client128\Modules\BonsDeReception\Service;

use Modules\Additional\Specifique\Client128\Modules\BonsDeReception\Repository\CreationBR;
use PDO;

class CreationSpecBRService
{
    /**
     * initTypeRecep
     *
     * @param  PDO $pdo
     * @param  string $order
     * @param  array<mixed> $orderLines
     * @return array<mixed>
     */
    public function initTypeRecep(PDO $pdo, string $order, array $orderLines): array
    {
        $newOrderLines    = [];

        if ((new CreationBR($pdo))->amountReceipt($order)['VALEUR'] == 'O') {
            // si le CS == 'O' alors la réception est forcément en montant
            foreach ($orderLines as $key => $value) {
                $newOrderLines[] = $value;
                $newOrderLines[$key]['LIGNE_RECUE_EN_MNT'] = '0x54';
            }
        } else {
            // sinon la réception est forcément en quantité
            foreach ($orderLines as $key => $value) {
                $newOrderLines[] = $value;
                $newOrderLines[$key]['LIGNE_RECUE_EN_QTE'] = '0x54';
            }
        }

        return $newOrderLines;
    }
}
