<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ProjectTask extends Model
{
    protected $fillable = [
        'project_id', 'parent_id', 'title', 'description',
        'assigned_to', 'assigned_by', 'priority', 'status',
        'due_date', 'estimated_hours', 'actual_hours', 'order',
        'linked_report_suggested'
    ];

    protected $casts = [
        'due_date' => 'date',
        'linked_report_suggested' => 'boolean',
    ];

    public function project()
    {
        return $this->belongsTo(Project::class);
    }

    public function assignee()
    {
        return $this->belongsTo(User::class, 'assigned_to');
    }

    public function assigner()
    {
        return $this->belongsTo(User::class, 'assigned_by');
    }

    public function parent()
    {
        return $this->belongsTo(ProjectTask::class, 'parent_id');
    }

    public function subtasks()
    {
        return $this->hasMany(ProjectTask::class, 'parent_id');
    }

    public function comments()
    {
        return $this->hasMany(ProjectTaskComment::class);
    }

    public function attachments()
    {
        return $this->hasMany(ProjectTaskAttachment::class);
    }

    public function timeLogs()
    {
        return $this->hasMany(ProjectTaskTimeLog::class);
    }
}
