<?php

namespace Modules\Additional\Specifique\Client37\Modules\GestionUtilisateur\Repository;

use Helpers\Outil\Sql;
use Modules\Administration\Repository\UtilisateurRepo;

class SpecUtilisateurRepo extends UtilisateurRepo
{
    /**
     * @param array<string> $user User as returned by getBaseQuery
     * @return array<mixed>
     */
    protected function formatUser(array $user)
    {
        $metadata = array_column($this->fetchAssocAll(
            "SELECT 
                CS_DON.VALEUR,
                DILISPEC.CODEDICO
            FROM DILISPEC with (nolock)
            LEFT JOIN CS_DON with(nolock) on DILISPEC.LIB01DICO = CS_DON.NUM_FIX
            WHERE 
                DILISPEC.CODEDICO IN (
                    'NCS_HASTUTIL_MAILRELSIGCDE', 
                    'NCS_HASTUTIL_COPIEMAILRELSIGCDE'
                )
                AND DILISPEC.TYPEDICO = 'BYCNWFPAR'
                AND CS_DON.COD_TAB = :table
                AND CS_DON.COD_ENR = :userId",
            ['userId' => $user['CODE'], 'table' => $user['Table']]
        ), 'CODEDICO', 'VALEUR');
        return parent::formatUser($user)
            + [
                'MAILRELSIGCDE' => Sql::toBool($metadata['NCS_HASTUTIL_MAILRELSIGCDE'] ?? false),
                'COPIEMAILRELSIGCDE' => Sql::toBool($metadata['NCS_HASTUTIL_COPIEMAILRELSIGCDE'] ?? false),
            ];
    }

    // public function getUser(string $userId)
    // {
    //     $table = $mode == 'S' ? 'HASTUTIL' : 'M' => 'UTILCREAT';
    //     return parent::getUser($userId)
    //         // Add field NCS_HASTUTIL_MAILRELSIGCDE & NCS_HASTUTIL_COPIEMAILRELSIGCDE
    //         +
    // }
}
