<?php

namespace Modules\SaveTheFood\Repositories;

use Illuminate\Database\Eloquent\Collection;
use Modules\SaveTheFood\Models\SaveTheFoodProduct;
use Modules\SaveTheFood\Repositories\Interfaces\SaveTheFoodRepositoryInterface;

class SaveTheFoodRepository implements SaveTheFoodRepositoryInterface
{
    public function __construct(
        private SaveTheFoodProduct $model
    ) {}

    public function all(): Collection
    {
        return $this->model->with('product')->get();
    }

    public function getFeatured(): Collection
    {
        return $this->model->with('product')->where('is_featured', true)->get();
    }

    public function getStats(): array
    {
        return [
            'total_products' => $this->model->count(),
            'total_stock' => $this->model->sum('stock_remaining'),
            'featured_count' => $this->model->where('is_featured', true)->count(),
        ];
    }
}
