<?php

namespace App\Repositories;

use App\Models\MoodEntry;

class MoodEntryRepository extends BaseRepository
{
    public function __construct(MoodEntry $model)
    {
        parent::__construct($model);
    }

    public function getUserMoods($userId, $limit = null)
    {
        $query = $this->model->where('user_id', $userId)->orderBy('entry_date', 'desc');
        if ($limit) {
            $query->limit($limit);
        }
        return $query->get();
    }

    public function getMoodStats($userId, $days = 30)
    {
        return $this->model->where('user_id', $userId)
            ->where('entry_date', '>=', now()->subDays($days))
            ->selectRaw('AVG(mood_score) as average, DATE(entry_date) as date')
            ->groupBy('date')
            ->orderBy('date')
            ->get();
    }
}
