<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Source extends Model
{
    protected $fillable = [
        'name',
        'description',
        'url',
        'status',
        'last_import_at',
    ];

    protected $casts = [
        'last_import_at' => 'datetime',
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
    ];

    /**
     * Ein Source hat viele Events.
     */
    public function events(): HasMany
    {
        return $this->hasMany(Event::class);
    }

    /**
     * Scope für aktive Quellen.
     */
    public function scopeActive($query)
    {
        return $query->where('status', 'active');
    }
}
