<?php
/**
 * Rule Class
 *
 * @version     1.0.$Revision:$
 * @version     SVN: $Id:$
 * @package     bplan-base/globals
 * @subpackage  Rules
 * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
 * @copyright   Copyright (C) 2025, 2026 bplan-solutions GmbH & Co. KG <https://www.bplan-solutions.de/>
 * /Δ\
 */

namespace BplanBase\Globals\Rules;

use Closure;
use Illuminate\Contracts\Validation\ValidationRule;


/**
 * Rule Class
 *
 * Stellt sicher, dass mindestens eins der beiden involvierten Felder einen Wert enthält.
 *
 * @version     1.0.0 / 2026-02-17
 * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
 */
class ArrayAtLeastOneRequired implements ValidationRule
{


/* +++ TRAITS +++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */


/* +++ CLASS CONSTANTS +++ ++++++++++++++++++++++++++++++++++++++++++++++++++ */


/* +++ OBJECT MEMBERS +++ +++++++++++++++++++++++++++++++++++++++++++++++++++ */


/* +++ CLASS MEMBERS +++ ++++++++++++++++++++++++++++++++++++++++++++++++++++ */


/* +++ OBJECT METHODS +++ +++++++++++++++++++++++++++++++++++++++++++++++++++ */


    /**
     * Run the validation rule.
     *
     * @param       string $attribute
     *
     * @param       mixed $value
     *
     * @param       \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString  $fail
     *
     * @return      void
     *
     * @version     1.0.0 / 2026-02-17
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     */
    public function validate(string $attribute, mixed $value, Closure $fail): void
    {
        $atLeastOneTrue = false;

        foreach ($value as $arrayElement) {
            if ($arrayElement == true) {
                $atLeastOneTrue = true;
            }
        }
        if ($atLeastOneTrue == false) {
            $fail(__('validation.required', ['attribute' => $attribute]));
        }
    } // validate()


/* +++ CLASS METHODS +++ ++++++++++++++++++++++++++++++++++++++++++++++++++++ */


} // class ArrayAtLeastOneRequired implements ValidationRule {}
