<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class OperationsTask extends Model
{
    use HasFactory;

    protected $fillable = [
        'order_item_id',
        'started_by_user_id',
        'started_at',
        'completed_by_user_id',
        'completed_at',
        'title',
        'status',
        'order_column',
    ];

    protected $casts = [
        'started_at' => 'datetime',
        'completed_at' => 'datetime',
    ];

    public function item()
    {
        return $this->belongsTo(OperationsOrderItem::class, 'order_item_id');
    }

    public function comments()
    {
        return $this->hasMany(OperationsTaskComment::class, 'task_id');
    }

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