<?php

namespace App\DataTables;

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

class GenderLookupDataTableEditor extends DataTablesEditor
{
    protected $model = GenderLookup::class;

    /**
     * Get create action validation rules.
     *
     * @return array
     */
    public function createRules()
    {
        return [
            //'firstame' => 'required|email|unique:' . $this->resolveModel()->getTable(),
            'firstame' => '',
            'country'  => '',
            'gender'  => '',
        ];
    }

    /**
     * Get edit action validation rules.
     *
     * @param Model $model
     * @return array
     */
    public function editRules(Model $model)
    {
        return [
            //'firstame' => 'required|email|unique:' . $this->resolveModel()->getTable(),
            'firstame' => '',
            'country'  => '',
            'gender'  => '',
        ];
    }

    /**
     * Override messages with custom messages
     *
     * @return array
     */
    public function editMessages()
    {
        return [
            'firstname'           => 'Bitte geben Sie den Namen ein',
            'country'             => 'Bitte geben Sie das Land ein',
            'gender'              => 'Bitte geben Sie das Geschlecht 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'] = $data['firstname'];

        return $data;
    }

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

        return $data;
    }
}
