<?php

namespace App\Models;

use App\Enums\RetentionOverrideScope;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class RetentionOverride extends Model
{
    /** @use HasFactory<\Database\Factories\RetentionOverrideFactory> */
    use HasFactory;

    protected $fillable = [
        'scope',
        'tenant_id',
        'event_id',
        'reason',
        'note',
        'created_by_id',
        'released_by_id',
        'released_at',
    ];

    protected $casts = [
        'scope' => RetentionOverrideScope::class,
        'released_at' => 'datetime',
    ];

    public function tenant(): BelongsTo
    {
        return $this->belongsTo(Tenant::class);
    }

    public function event(): BelongsTo
    {
        return $this->belongsTo(Event::class);
    }

    public function createdBy(): BelongsTo
    {
        return $this->belongsTo(User::class, 'created_by_id');
    }

    public function releasedBy(): BelongsTo
    {
        return $this->belongsTo(User::class, 'released_by_id');
    }

    public function isActive(): bool
    {
        return $this->released_at === null;
    }
}
