<?php

namespace App\Http\Requests\Company;

use Illuminate\Foundation\Http\FormRequest;

class UpdateCompanyRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
     public function authorize()
    {
        return auth()->check();
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, mixed>
     */
    public function rules()
    {
        return [
            'name'=>'required',
            'description'=>'required',
            'da_description'=>'required',
            'pa_description'=>'required',
            'logo'=>'nullable|image|mimes:png,jpg,jpeg,gif',
            'da_logo'=>'nullable|image|mimes:png,jpg,jpeg,gif',
            'footer_logo'=>'nullable|image|mimes:png,jpg,jpeg,gif',
            'da_footer_logo'=>'nullable|image|mimes:png,jpg,jpeg,gif'
        ];
    }

      public function requestHandler(){
      $allRequest = $this->all();
      if($this->logo){
      $allRequest['logo'] = upload_file($this->logo);
       delete_file($this->old_logo);
      }else{
      $allRequest['logo'] = $this->old_logo;
      }


       if($this->da_logo){
      $allRequest['da_logo'] = upload_file($this->da_logo);
       delete_file($this->da_old_logo);
      }else{
      $allRequest['da_logo'] = $this->da_old_logo;
      }


         if($this->da_footer_logo){
      $allRequest['da_footer_logo'] = upload_file($this->da_footer_logo);
       delete_file($this->old_da_footer_logo);
      }else{
      $allRequest['da_footer_logo'] = $this->old_da_footer_logo;
      }

    if($this->footer_logo){
      $allRequest['footer_logo'] = upload_file($this->footer_logo);
       delete_file($this->old_footer_logo);
      }else{
      $allRequest['footer_logo'] = $this->old_footer_logo;
      }


      return $allRequest;
    }
}