<?php


namespace App\Http\Requests\Api;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class SubscriptionStoreRequest extends FormRequest
{
    const RC = "residential_complex";
    const DEVELOPER = "developer";
    const SITE = "site";

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $data = parent::all();
        return [
            'type' => 'required|in:'
                . self::RC .
                "," . self::DEVELOPER .
                "," . self::SITE,
            'value' => [Rule::requiredIf(function () use ($data) {
                if ($data['type'] == self::RC || $data['type'] == self::DEVELOPER) {
                    return true;
                }

                return false;
            })],
            'email' =>  'required'
        ];
    }
}
