//
//  MockData+Polls.swift
//  SportsTimeTests
//
//  Mock data extensions for poll-related tests
//

import Foundation
@testable import SportsTime

// MARK: - Trip Mock

extension Trip {
    /// Creates a mock trip for testing
    static func mock(
        id: UUID = UUID(),
        name: String = "Test Trip",
        cities: [String] = ["Boston", "New York"],
        startDate: Date = Date(),
        games: [String] = []
    ) -> Trip {
        let stops = cities.enumerated().map { index, city in
            TripStop.mock(
                stopNumber: index + 1,
                city: city,
                arrivalDate: startDate.addingTimeInterval(Double(index) * 86400),
                departureDate: startDate.addingTimeInterval(Double(index + 1) * 86400),
                games: games
            )
        }

        return Trip(
            id: id,
            name: name,
            preferences: TripPreferences(
                planningMode: .dateRange,
                sports: [.mlb],
                startDate: startDate,
                endDate: startDate.addingTimeInterval(86400 * Double(cities.count))
            ),
            stops: stops
        )
    }
}

// MARK: - TripStop Mock

extension TripStop {
    /// Creates a mock trip stop for testing
    static func mock(
        stopNumber: Int = 1,
        city: String = "Boston",
        state: String = "MA",
        arrivalDate: Date = Date(),
        departureDate: Date? = nil,
        games: [String] = []
    ) -> TripStop {
        TripStop(
            stopNumber: stopNumber,
            city: city,
            state: state,
            arrivalDate: arrivalDate,
            departureDate: departureDate ?? arrivalDate.addingTimeInterval(86400),
            games: games
        )
    }
}

// MARK: - TripPoll Mock

extension TripPoll {
    /// Creates a mock poll for testing
    static func mock(
        id: UUID = UUID(),
        title: String = "Test Poll",
        ownerId: String = "mockOwner",
        shareCode: String? = nil,
        tripCount: Int = 2,
        trips: [Trip]? = nil
    ) -> TripPoll {
        let tripSnapshots = trips ?? (0..<tripCount).map { index in
            Trip.mock(name: "Trip \(index + 1)", cities: ["City\(index)A", "City\(index)B"])
        }

        return TripPoll(
            id: id,
            title: title,
            ownerId: ownerId,
            shareCode: shareCode ?? TripPoll.generateShareCode(),
            tripSnapshots: tripSnapshots
        )
    }
}

// MARK: - PollVote Mock

extension PollVote {
    /// Creates a mock vote for testing
    static func mock(
        id: UUID = UUID(),
        pollId: UUID = UUID(),
        odg: String = "mockVoter",
        rankings: [Int] = [0, 1]
    ) -> PollVote {
        PollVote(
            id: id,
            pollId: pollId,
            odg: odg,
            rankings: rankings
        )
    }
}

// MARK: - PollResults Mock

extension PollResults {
    /// Creates mock results for testing
    static func mock(
        poll: TripPoll? = nil,
        votes: [PollVote]? = nil
    ) -> PollResults {
        let testPoll = poll ?? TripPoll.mock()
        let testVotes = votes ?? [
            PollVote.mock(pollId: testPoll.id, odg: "voter1", rankings: [0, 1]),
            PollVote.mock(pollId: testPoll.id, odg: "voter2", rankings: [1, 0])
        ]

        return PollResults(poll: testPoll, votes: testVotes)
    }
}
