<?php

namespace App\Models;

use App\Traits\HasSlugHistory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;

class Designer extends Model
{
    use HasSlugHistory;

    protected $fillable = [
        'name',
        'slug',
        'description',
        'website',
        'founded_date',
        'headquarters',
    ];

    protected $casts = [
        'founded_date' => 'date',
    ];

    protected static function boot()
    {
        parent::boot();

        static::creating(function ($designer) {
            if (empty($designer->slug)) {
                $designer->slug = Str::slug($designer->name);
            }
        });
    }
    
    public function rides()
    {
        return $this->hasMany(Ride::class);
    }
}