<?php

namespace App\Rules\Fragments;

use App\Rules\MetroIdentity;
use App\Rules\RegionIdentity;
use App\Rules\SubregionIdentity;

/**
 * Shared rule-array fragments for the region/subregion/metro regionality
 * hierarchy. Spread into a Validator rules array: ...Regionality::full()
 */
final class Regionality
{

    /**
     * The complete cascade used by the flag/special endpoints: each narrower
     * level is only validated when its parent level was supplied.
     */
    public static function full(): array
    {
        return [
            'region_id'    => [ new RegionIdentity ],
            'subregion_id' => [ new SubregionIdentity, 'exclude_without:region_id' ],
            'metro_id'     => [ new MetroIdentity, 'exclude_without:subregion_id' ],
        ];
    }

    /**
     * The optional region/subregion pair used by the firewall endpoints.
     */
    public static function nullablePair(): array
    {
        return [
            'region_id'    => [ 'nullable', new RegionIdentity ],
            'subregion_id' => [ 'nullable', new SubregionIdentity ],
        ];
    }
}
