<?php

namespace App\Models;

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

class Document extends Model
{
    use HasFactory;

    protected $fillable = [
        'id',
        'title',
        'description',
        'comments',
        'file_path',
        'meta_tags',
        'created_by',
        'workflow_id',
        'status',
        'started_workflow',
        'created_at',
        'updated_at',
    ];

    protected $casts = [
        'meta_tags' => 'array',
        'started_workflow' => 'boolean',
    ];

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

    public function workflow()
    {
        return $this->belongsTo(Workflow::class, 'workflow_id');
    }

    public function workflowInstances()
    {
        return $this->hasMany(WorkflowInstance::class);
    }

    public function tasks()
    {
        return $this->hasMany(\App\Models\WorkflowTask::class);
    }
}
