<?php

namespace Modules\Bms\Entities;

use Illuminate\Database\Eloquent\Model;

class BmsTaskTemplate extends Model
{
    protected $table = 'bms_task_templates';

    protected $fillable = [
        'business_id', 'title', 'department', 'event_type', 'offset_days',
        'offset_hour', 'assignee_role', 'description', 'is_active', 'sort_order',
    ];

    protected $casts = [
        'offset_days' => 'integer',
        'offset_hour' => 'integer',
        'is_active'   => 'boolean',
        'sort_order'  => 'integer',
    ];

    /** Templates that apply to a given event type (event_type match OR null = all). */
    public function scopeForEventType($query, ?string $eventType)
    {
        return $query->where(function ($q) use ($eventType) {
            $q->whereNull('event_type');
            if ($eventType) {
                $q->orWhere('event_type', $eventType);
            }
        });
    }
}
