<?php

namespace App\Http\Requests\Sell;

use App\Http\Requests\Request;
use Illuminate\Database\Query\Builder;
use Illuminate\Validation\Rule;

class AgentCustomerSaveRequest extends Request
{
    /**
     * 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()
    {
        if (!$this->ajax()) {
            return [];
        }

        return [
            'customer_name' => [
                'required',
                Rule::unique('agent_customer')->where(function (Builder $query) {
                    return $query->where('deleted_at', null);
                })->ignore($this->route('id'))
            ],
            'domain' => 'required',
            'contact_user' => 'required',
            'contact_phone' => 'required',
            'user_id' => 'nullable',
            'remark' => 'nullable',
        ];

    }


    public function attributes()
    {
        return [
            'customer_name' => '客户名称',
            'domain' => '域名',
            'contact_user' => '联系人',
            'contact_phone' => '联系方式',
        ];
    }
}