<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

namespace App\Models;
use App\Models\NoticeUpdate;
use Illuminate\Database\Eloquent\Model;
class File extends Model
{
    protected $fillable = [
        'category_id',
        'year',
        'type',
        'name',
        'act_number',
        'description',
        'status',
        'active',
        'created_by',
        'updated_by'
    ];

    public $timestamps = true;

    public function category()
    {
        return $this->belongsTo(Category::class);
    }

    public function notices()
    {
        return $this->hasMany(NoticeUpdate::class);
    }

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

    public function statusHistory()
    {
        return $this->hasMany(Status::class);
    }
    public function stages()
    {
        return $this->belongsToMany(Stage::class, 'file_stages')
                    ->withPivot('des', 'created_by', 'updated_by', 'active')
                    ->withTimestamps();
    }
    public function user_created()
    {
        return $this->belongsTo(User::class, 'created_by');
    }
    public function user_updated()
    {
        return $this->belongsTo(User::class, 'updated_by');
    }
    public function noticeUpdates()
    {
        return $this->hasMany(NoticeUpdate::class, 'file_id');
    }
    public function currentStage()
    {
        return $this->hasOne(FileStage::class, 'file_id')
            ->where('active', true)
            ->with('stage')
    ->latest();
    }


}
