<?php

namespace App\Repositories\Eloquent;

use App\Models\Category;
use Illuminate\Database\Eloquent\Model;

class CategoryRepository extends BaseRepository
{
    protected function resolveModel(): Model
    {
        return new Category();
    }

    public function findBySlug(string $slug): ?Category
    {
        return $this->model->where('slug', $slug)->first();
    }

    public function getActive()
    {
        return $this->model->active()->ordered()->get();
    }

    public function getWithProducts()
    {
        return $this->model->with(['products' => function ($query) {
            $query->active();
        }])->active()->ordered()->get();
    }

    public function getActiveWithProductCount()
    {
        return $this->model->withCount(['products' => function ($query) {
            $query->active();
        }])->active()->ordered()->get();
    }

    public function findTrashed(int $id): ?Category
    {
        return $this->model->withTrashed()->find($id);
    }
}
