<?php

namespace App\DataTables;

use App\Artist;
use Illuminate\Validation\Rule;
use Yajra\DataTables\DataTablesEditor;
use Illuminate\Database\Eloquent\Model;

class ArtistDataTableEditor extends DataTablesEditor
{
    protected $model = Artist::class;

    /**
     * Get create action validation rules.
     *
     * @return array
     */
    public function createRules()
    {
        return [
            'status'             => '',
            'firstname_de'       => '',
            'firstname_en'       => '',
            'firstname_fr'       => '',
            'lastname_de'        => '',
            'lastname_en'        => '',
            'lastname_fr'        => '',
            'born_date'          => '',
            'born_location_de'   => '',
            'born_location_en'   => '',
            'born_location_fr'   => '',
            'died_date'          => '',
            'died_location_de'   => '',
            'died_location_en'   => '',
            'died_location_fr'   => '',
            'editor'             => '',
        ];
    }

    /**
     * Get edit action validation rules.
     *
     * @param Model $model
     * @return array
     */
    public function editRules(Model $model)
    {
        return [
            'status'             => 'sometimes',
            'firstname_de'       => '',
            'firstname_en'       => '',
            'firstname_fr'       => '',
            'lastname_de'        => '',
            'lastname_en'        => '',
            'lastname_fr'        => '',
            'born_date'          => '',
            'born_location_de'   => '',
            'born_location_en'   => '',
            'born_location_fr'   => '',
            'died_date'          => '',
            'died_location_de'   => '',
            'died_location_en'   => '',
            'died_location_fr'   => '',
            'editor'             => '',
        ];
    }

    public function editMessages()
    {
        return [
            'status.required' => 'Bitte wählen Sie den Status aus',
            'firstname_de.required' => 'Bitte geben Sie den Vornamen DE ein',
            'firstname_en.required' => 'Bitte geben Sie den Vornamen EN ein',
            'firstname_fr.required' => 'Bitte geben Sie den Vornamen FR ein',
            'lastname_de.required' => 'Bitte geben Sie den Nachnamen DE ein',
            'lastname_en.required' => 'Bitte geben Sie den Nachnamen EN ein',
            'lastname_fr.required' => 'Bitte geben Sie den Nachnamen FR ein',
            'born_date.required' => 'Bitte geben Sie das Geburtsdateum ein',
            'born_location_de.required' => 'Bitte geben Sie den Geburtsort DE ein',
            'born_location_en.required' => 'Bitte geben Sie den Geburtsort EN ein',
            'born_location_fr.required' => 'Bitte geben Sie den Geburtsort FR ein',
        ];
    }

    /**
     * Get remove action validation rules.
     *
     * @param Model $model
     * @return array
     */
    public function removeRules(Model $model)
    {
        return [];
    }

    /**
     * Pre-create action event hook.
     *
     * @param Model $model
     * @return array
     */
    public function creating(Model $model, array $data)
    {
        //$data['firstname_en'] = $data['firstname_en'];

        //return $data;
        return $data;
    }

    /**
     * Pre-update action event hook.
     *
     * @param Model $model
     * @return array
     */
    public function updating(Model $model, array $data)
    {
        /*if (empty($data['firstname_en'])) {
            unset($data['firstname_en']);
        } else {
            $data['firstname_en'] = $data['firstname_en'];
        }

        return $data;*/

        return $data;
    }
}
