<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

use App\Models\ReportHistory;

class Report extends Model
{
    use HasFactory;

    protected $fillable = [
        'reporter_id',
        'target_type',
        'target_id',
        'reason',
        'details',
        'status',
        'moderator_note',
        'last_moderated_by_id',
        'last_moderated_at',
    ];

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

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

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

    public function historyEntries(): HasMany
    {
        return $this->hasMany(ReportHistory::class)->latest('id');
    }
}
