<?php

namespace Modules\Stock\Helper;

use Helpers\Outil\Roles;
use Modules\GlobalApplication\Repository\LicenceOxalys;
use Modules\Stock\Service\ParametrageService;
use PDO;

class RulesHelper
{
    public static function hasStockAccessRights(PDO $pdo): bool
    {
        return Roles::droitsUtilisateur($pdo, '87kjnbqsiy') && (new LicenceOxalys($pdo))->stockActive();
    }

    public static function hasParametrageAccessRights(PDO $pdo): bool
    {
        return (new LicenceOxalys($pdo))->stockActive() && Roles::droitsUtilisateur($pdo, 'HA_PARAM') && Roles::droitsUtilisateur($pdo, 'HA_GLOBSYS');
    }

    public static function hasImportUniverselAccessRights(PDO $pdo): bool
    {
        return self::hasStockAccessRights($pdo) && Roles::droitsUtilisateur($pdo, 'ST_DS_UNI');
    }

    public static function hasMouvementAccessRights(PDO $pdo): bool
    {
        return self::hasStockAccessRights($pdo) && Roles::droitsUtilisateur($pdo, 'ST_MV_VIS');
    }

    public static function hasBonEntreeAccessRights(PDO $pdo): bool
    {
        return self::hasStockAccessRights($pdo) && Roles::droitsUtilisateur($pdo, 'ST_BE_CMV');
    }

    public static function hasBonSortieAccessRights(PDO $pdo): bool
    {
        return self::hasStockAccessRights($pdo) && Roles::droitsUtilisateur($pdo, 'ST_BS_CMV');
    }

    public static function hasBonSortieImpressionValoriseeDroits(PDO $pdo): bool
    {
        return ((new ParametrageService($pdo))->isVisibilitePrixActif() || Roles::droitsUtilisateur($pdo, 'ST_PRX_ACC')) && Roles::droitsUtilisateur($pdo, 'ST_BS_I_V');
    }

    public static function hasBonTransfertAccessRights(PDO $pdo): bool
    {
        return RulesHelper::hasStockAccessRights($pdo) && Roles::droitsUtilisateur($pdo, 'ST_BT_CMV');
    }

    public static function hasInvAccessRights(PDO $pdo): bool
    {
        return RulesHelper::hasStockAccessRights($pdo) && Roles::droitsUtilisateur($pdo, 'ST_IN_CMV');
    }

    public static function hasDemandeServiceAccessRights(PDO $pdo): bool
    {
        return RulesHelper::hasStockAccessRights($pdo) && Roles::droitsUtilisateur($pdo, 'ST_DS_SMV');
    }

    public static function hasIndisponibiliteAccessRights(PDO $pdo): bool
    {
        return RulesHelper::hasStockAccessRights($pdo) && Roles::droitsUtilisateur($pdo, 'ST_DISPO');
    }
}
