<?php

namespace App\Http\Requests\Api;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Request;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Contracts\Validation\Validator;


class StoreContractRequest extends FormRequest
{
    /**
     * 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(Request $request)
    {
        $rules['title'] = 'required';
        $rules['office_id'] = 'required';
        $rules['office_fa'] = 'required';
        $rules['status_fa'] = 'required';
        $rules['status_id'] = 'required';
        $rules['province_id'] = 'required|integer|min:1';
        $rules['contract_date'] = 'required';
        $rules['contract_credit'] = 'required';
        $rules['contract_peymankar'] = 'required';
        // $rules['contract_credit_national'] = 'required';
        $rules['contract_moshaver_tarahi'] = 'required';
        $rules['contract_moshaver_nezarat'] = 'required';
        // $rules['contract_mojavez'] = 'required';
        // $rules['contract_mojavez_fa'] = 'required';
        return $rules;
    }

    public function messages()
    {
        return [
            'province_id.min' => 'لطفا استان را انتخاب کنید.'
        ];
    }

    public function attributes()
    {
        return [
            'title' => 'عنوان قرارداد',
            'office_id' => 'اداره کل',
            'office_fa' => 'اداره کل',
            'status_fa' => 'وضعیت قرارداد',
            'status_id' => 'وضعیت قرارداد',
            'province_fa' => 'استان',
            'province_id' => 'استان',
            'contract_date' => 'تاریخ انعقاد قرارداد',
            'contract_credit' => 'مبلغ کل قرارداد',
            'contract_peymankar' => 'نام پیمانکار',
            'contract_credit_national' => 'مبلغ اعتبار ملی',
            'contract_moshaver_tarahi' => 'نام مشاور طراحی',
            'contract_moshaver_nezarat' => 'نام مشاور نظارت',

        ];
    }

    protected function failedValidation(Validator $validator)
    {
        throw new HttpResponseException(response()->json([
            'erorr' => $validator->errors()
        ], 400));
    }
}
