<?php

namespace Modules\Bms\Entities;

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

class BmsTask extends Model
{
    protected $table = 'bms_tasks';

    protected $fillable = [
        'business_id', 'booking_id', 'template_id', 'title', 'department',
        'due_at', 'assignee_id', 'assignee_role', 'status', 'completed_at',
        'completed_by', 'notes', 'received_at', 'read_at', 'accepted_at', 'accepted_by',
    ];

    protected $casts = [
        'due_at'       => 'datetime',
        'completed_at' => 'datetime',
        'received_at'  => 'datetime',
        'read_at'      => 'datetime',
        'accepted_at'  => 'datetime',
    ];

    public function booking(): BelongsTo
    {
        return $this->belongsTo(BmsBooking::class, 'booking_id');
    }

    public function events()
    {
        return $this->hasMany(BmsTaskEvent::class, 'task_id')->latest();
    }
}
