//
//  DayViewViewModelTests.swift
//  ReflectTests
//
//  Unit tests for DayViewViewModel.countEntries — verifies safe counting
//  across various grouped dictionary shapes (TDD for force-unwrap fix).
//

import XCTest
import SwiftData
@testable import Reflect

@MainActor
final class DayViewViewModelTests: XCTestCase {

    func testCountEntries_EmptyGrouped() {
        let grouped: [Int: [Int: [MoodEntryModel]]] = [:]
        XCTAssertEqual(DayViewViewModel.countEntries(in: grouped), 0)
    }

    func testCountEntries_SingleYearSingleMonth() {
        let entry = MoodEntryModel(forDate: Date(), mood: .great, entryType: .listView)
        let grouped: [Int: [Int: [MoodEntryModel]]] = [2026: [2: [entry]]]
        XCTAssertEqual(DayViewViewModel.countEntries(in: grouped), 1)
    }

    func testCountEntries_MultipleYearsAndMonths() {
        let e1 = MoodEntryModel(forDate: Date(), mood: .great, entryType: .listView)
        let e2 = MoodEntryModel(forDate: Date(), mood: .good, entryType: .listView)
        let e3 = MoodEntryModel(forDate: Date(), mood: .bad, entryType: .listView)
        let grouped: [Int: [Int: [MoodEntryModel]]] = [
            2025: [12: [e1, e2]],
            2026: [1: [e3], 2: [e1, e2, e3]]
        ]
        XCTAssertEqual(DayViewViewModel.countEntries(in: grouped), 6)
    }

    func testCountEntries_YearWithEmptyMonth() {
        let grouped: [Int: [Int: [MoodEntryModel]]] = [2026: [1: []]]
        XCTAssertEqual(DayViewViewModel.countEntries(in: grouped), 0)
    }
}
