<?php

namespace App\Models;

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

class AccessRevocationLog extends Model
{
    use HasFactory;

    protected $fillable = [
        'employee_access_detail_id', 'revoked_by', 'revoked_at', 'method',
        'previous_status', 'notes', 'ip_address', 'user_agent'
    ];

    protected $casts = [
        'revoked_at' => 'datetime',
    ];

    public function employeeAccessDetail()
    {
        return $this->belongsTo(EmployeeAccessDetail::class);
    }

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

    public function employee()
    {
        return $this->employeeAccessDetail->employee;
    }

    public function accessCatalog()
    {
        return $this->employeeAccessDetail->accessCatalog;
    }

    public function scopeAutomatic($query)
    {
        return $query->where('method', 'automatic');
    }

    public function scopeManual($query)
    {
        return $query->where('method', 'manual');
    }
}