<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class ServiceAgendaItem extends Model
{
    use HasFactory;

    protected $fillable = [
        'service_id',
        'cts_agenda_item_id',
        'position',
        'title',
        'type',
        'note',
        'duration',
        'start',
        'is_before_event',
        'responsible',
        'service_song_id',
        'sort_order',
    ];

    protected function casts(): array
    {
        return [
            'responsible' => 'array',
            'is_before_event' => 'boolean',
        ];
    }

    public function service(): BelongsTo
    {
        return $this->belongsTo(Service::class);
    }

    public function serviceSong(): BelongsTo
    {
        return $this->belongsTo(ServiceSong::class);
    }

    public function slides(): HasMany
    {
        return $this->hasMany(Slide::class, 'service_agenda_item_id');
    }

    public function scopeVisible(Builder $query): void
    {
        $query->where('is_before_event', false);
    }
}
