<?php

namespace App\Http\Controllers;

use App\Http\Requests\MoodRequest;
use App\Services\MoodService;
use App\Repositories\MoodEntryRepository;

class MoodController extends Controller
{
    protected $moodService;
    protected $moodRepo;

    public function __construct(MoodService $moodService, MoodEntryRepository $moodRepo)
    {
        $this->moodService = $moodService;
        $this->moodRepo = $moodRepo;
    }

    public function index()
    {
        $moods = $this->moodRepo->getUserMoods(auth()->id());
        return view('mood.index', compact('moods'));
    }

    public function create()
    {
        return view('mood.create');
    }

    public function store(MoodRequest $request)
    {
        $this->moodService->createMood($request->validated());
        return redirect()->route('moods.index')->with('success', 'Mood entry saved.');
    }

    public function show($id)
    {
        $mood = $this->moodRepo->find($id);
        $this->authorize('view', $mood);
        return view('mood.show', compact('mood'));
    }
}
