<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Validator;

class CustomValidationServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        // Slug validation rule
        Validator::extend('slug', function ($attr, $value, $param) {
            if (! preg_match('/^[a-zA-Z0-9\-_\.]+$/', $value)) {
                return false;
            }

            return true;
        });

        // Predefined words validation rule
        Validator::extend('predefined', function ($attr, $value, $param) {
            $predefined = config('predefined-words', '');
            $predefinedArray = explode(',', $predefined);

            if (in_array(strtolower($value), $predefinedArray)) {
                return false;
            }

            return true;
        });

        // Valid alpha validation rule (first character cannot be numeric)
        Validator::extend('validalpha', function ($attr, $value, $param) {
            $firstChar = substr($value, 0, 1);
            if (is_numeric($firstChar)) {
                return false;
            }

            return true;
        });
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
