<?php

namespace App\Models;

use App\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;

class EmployeeDocument extends Model
{
    use BelongsToTenant;

    protected $fillable = [
        'tenant_id',
        'employee_id',
        'document_type',
        'document_number',
        'issue_date',
        'expiry_date',
        'issued_at',
        'attachment_path',
        'reminder_enabled',
        'parent_document_id',
        'version_number',
        'is_current',
        'status',
        'verified_by',
        'verified_at',
        'notes',
    ];

    protected $casts = [
        'issue_date' => 'date',
        'expiry_date' => 'date',
        'reminder_enabled' => 'boolean',
        'is_current' => 'boolean',
        'verified_at' => 'datetime',
    ];

    public function employee()
    {
        return $this->belongsTo(Employee::class);
    }

    public function previousVersion()
    {
        return $this->belongsTo(self::class, 'parent_document_id');
    }

    public function versions()
    {
        return $this->hasMany(self::class, 'parent_document_id')->orderByDesc('version_number');
    }

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