<?php

namespace App\Modules\HR\EmployeeSelfService\Repositories;

use App\Modules\HR\Employees\Models\EmployeeAssetAssignment;
use App\Modules\HR\Employees\Models\EmployeeDocument;
use App\Modules\HR\Training\Models\TrainingEnrollment;
use Illuminate\Support\Collection;

class SelfServicePortalRepository
{
    public function documents(int $employeeId): Collection
    {
        return EmployeeDocument::query()
            ->where('employee_id', $employeeId)
            ->orderByDesc('id')
            ->get();
    }

    public function document(int $employeeId, int $id): ?EmployeeDocument
    {
        return EmployeeDocument::query()
            ->where('employee_id', $employeeId)
            ->find($id);
    }

    public function training(int $tenantId, int $employeeId): Collection
    {
        return TrainingEnrollment::query()
            ->where('tenant_id', $tenantId)
            ->where('employee_id', $employeeId)
            ->with('session.course')
            ->orderByDesc('id')
            ->get();
    }

    public function assets(int $tenantId, int $employeeId): Collection
    {
        return EmployeeAssetAssignment::query()
            ->where('tenant_id', $tenantId)
            ->where('employee_id', $employeeId)
            ->orderByDesc('assigned_at')
            ->get();
    }
}
