<?php

namespace App\Trait;

use Illuminate\Database\Eloquent\Builder;

/**
 * Shared "is this file worth reviewing" logic for the two evidence origins
 * (ContactMessageAttachment and Document). A file is non-productive ("junk")
 * when a human has excluded it or when the AI verify/filter step skipped it
 * (the verify step stamps evidence_status = 'skipped' for non-DSAR records,
 * signature images, and documents with no relevant pages).
 *
 * Both models expose `evidence_excluded` and `evidence_status`; only
 * ContactMessageAttachment has `evidence_is_dsar_doc`, so it is deliberately
 * not referenced in the shared query scopes.
 */
trait HasEvidenceProductivity
{
    public function isEvidenceExcluded(): bool
    {
        return (bool) $this->evidence_excluded
            || $this->evidence_status === 'skipped';
    }

    public function isEvidenceProductive(): bool
    {
        return !$this->isEvidenceExcluded();
    }

    public function scopeProductive(Builder $query): void
    {
        $query->where('evidence_excluded', false)
            ->where(fn (Builder $s) => $s->whereNull('evidence_status')->orWhere('evidence_status', '!=', 'skipped'));
    }

    public function scopeExcluded(Builder $query): void
    {
        $query->where(fn (Builder $q) => $q->where('evidence_excluded', true)->orWhere('evidence_status', 'skipped'));
    }
}
