<?php

namespace Kylin\LawCase\Repositories;

use Kylin\LawCase\Models\Document;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;

/**
 * 文档仓储
 *
 * 封装文档数据查询逻辑。
 */
class DocumentRepository
{
    public function getByCase(int $caseId, array $filters = [], int $perPage = 15): LengthAwarePaginator
    {
        $query = Document::where('case_id', $caseId)->with('uploader');

        if (!empty($filters['doc_type'])) {
            $query->where('doc_type', $filters['doc_type']);
        }

        return $query->orderByDesc('created_at')->paginate($perPage);
    }
}
