<?php

namespace App\Http\Requests\Api\Checkout;

use Illuminate\Foundation\Http\FormRequest;

class CheckoutRequest extends FormRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'type' => 'required|in:ready_solutions,single_products',
            'delivery_type' => 'required|in:delivery,pickup',

            'branch_id' => 'required_if:delivery_type,pickup|exists:branches,id',
            'client_type' => 'required|in:physical,legal',
            'client_information' => 'required_if:client_type,physical|array',
            'client_information.full_name' => 'required_if:client_type,physical|string',
            'client_information.phone' => 'required_if:client_type,physical|numeric',

            'client_information.director_full_name' => 'required_if:client_type,legal|string',
            'client_information.company_name' => 'required_if:client_type,legal|string',
            'client_information.inn' => 'required_if:client_type,legal|string',
            'client_information.bank_name' => 'required_if:client_type,legal|string',
            'client_information.mfo' => 'required_if:client_type,legal|string',
            'client_information.oked' => 'required_if:client_type,legal|string',
            'client_information.payment_account' => 'required_if:client_type,legal|string',
            'client_information.address' => 'required_if:client_type,legal|string',
            'client_information.email' => 'nullable|email',
            'client_information.phone' => 'required_if:client_type,legal|numeric', //

            'client_information.jshir' => 'required_if:client_type,physical|numeric', //
            'client_information.series' => 'required_if:client_type,physical', //

            'address' => 'required_if:delivery_type,delivery|array',
            'address.city_id' => 'required_if:delivery_type,delivery|exists:cities,id',
            'address.address' => 'required_if:delivery_type,delivery|string',
            'address.home' => 'nullable',
            'address.landmark' => 'nullable',

            'with_installation' => 'required_if:type,ready_solutions|boolean',
            'payment_type' => 'required|in:cash,bank,click,payme',
            'with_didox' => 'required_if:payment_type,bank|boolean',

            'products' => 'required|array',
            'products.*.id' => 'required|exists:products,id',
            'products.*.count' => 'required|integer|min:1',
        ];
    }
}
