<?php

namespace App\Models;

use App\Services\Search\LocationConfigurator;
use Illuminate\Database\Eloquent\Model;
use ScoutElastic\Searchable;

class Location extends Model {

    use Searchable;

    protected $indexConfigurator = LocationConfigurator::class;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name',
    ];

    public function books() {
        return $this->hasMany(Book::class);
    }

    protected $mapping = [
        'properties' => [
            'name' => [
                'type' => 'text',
                // Also you can configure multi-fields, more details you can find here https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-fields.html
                'fields' => [
                    'raw' => [
                        'type' => 'keyword',
                    ]
                ]
            ],
        ]
    ];
}
