<?php

namespace App\Modules\Quotes;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Quote extends Model
{
    use SoftDeletes;

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'quotes';

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

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [];

    /**
     * Get a random quote.
     *
     * @return Quote|null
     */
    public static function getRandomQuote()
    {
        return static::inRandomOrder()->first();
    }

    /**
     * Check if a quote with the given text already exists.
     *
     * @param string $text
     * @return bool
     */
    public static function existsByText($text)
    {
        return static::where('text', $text)->exists();
    }
}