import XCTest
@testable import AIStudyApp

final class StudyHomeViewModelTests: XCTestCase {

    var vm: StudyHomeViewModel!

    override func setUp() {
        super.setUp()
        vm = StudyHomeViewModel()
    }

    override func tearDown() {
        vm = nil
        super.tearDown()
    }

    func testInitialState_hasFiveTasks() {
        XCTAssertEqual(vm.tasks.count, 5)
    }

    func testInitialState_twoTasksDone() {
        XCTAssertEqual(vm.doneCount, 2)
    }

    func testProgress_calculatesCorrectly() {
        XCTAssertEqual(vm.progress, 0.4, accuracy: 0.01)
    }

    func testToggleTask_changesDoneCount() {
        let task = vm.tasks.first(where: { !$0.d })!
        vm.toggleTask(task)
        XCTAssertEqual(vm.doneCount, 3)
    }

    func testToggleTask_togglingBackRestoresCount() {
        let task = vm.tasks.first(where: { $0.d })!
        vm.toggleTask(task)
        XCTAssertEqual(vm.doneCount, 1)
    }

    func testDoneMinutes_sumsCompletedTasks() {
        XCTAssertEqual(vm.doneMinutes, 25) // 10 + 15
    }

    func testRemainingMinutes_sumsPendingTasks() {
        XCTAssertEqual(vm.remainingMinutes, 30) // 8 + 12 + 10
    }

    func testToggleTask_updatesProgress() {
        let task = vm.tasks.first(where: { !$0.d })!
        vm.toggleTask(task)
        XCTAssertEqual(vm.progress, 0.6, accuracy: 0.01)
    }

    func testWeekActivity_hasSevenDays() {
        XCTAssertEqual(vm.weekActivity.count, 7)
        XCTAssertEqual(vm.dayLabels.count, 7)
    }
}
