import { describe, it, expect } from 'vitest';
import { DEFAULT_SETTINGS, DEFAULT_STATE } from './kuldvillak';
import type { Team, Round, Question, GameSettings } from './kuldvillak';

describe('Kuldvillak Types', () => {
    describe('DEFAULT_SETTINGS', () => {
        it('should have correct number of rounds', () => {
            expect(DEFAULT_SETTINGS.numberOfRounds).toBe(2);
        });

        it('should have 5 point values', () => {
            expect(DEFAULT_SETTINGS.pointValues).toHaveLength(5);
            expect(DEFAULT_SETTINGS.pointValues).toEqual([10, 20, 30, 40, 50]);
        });

        it('should have 6 categories per round', () => {
            expect(DEFAULT_SETTINGS.categoriesPerRound).toBe(6);
        });

        it('should have 5 questions per category', () => {
            expect(DEFAULT_SETTINGS.questionsPerCategory).toBe(5);
        });

        it('should have daily doubles configuration', () => {
            expect(DEFAULT_SETTINGS.dailyDoublesPerRound).toEqual([1, 2]);
        });

        it('should enable final round by default', () => {
            expect(DEFAULT_SETTINGS.enableFinalRound).toBe(true);
        });

        it('should allow negative scores by default', () => {
            expect(DEFAULT_SETTINGS.allowNegativeScores).toBe(true);
        });

        it('should have 6 max teams', () => {
            expect(DEFAULT_SETTINGS.maxTeams).toBe(6);
        });

        it('should have default timer of 5 seconds', () => {
            expect(DEFAULT_SETTINGS.defaultTimerSeconds).toBe(5);
        });

        it('should have answer reveal of 5 seconds', () => {
            expect(DEFAULT_SETTINGS.answerRevealSeconds).toBe(5);
        });
    });

    describe('DEFAULT_STATE', () => {
        it('should start in lobby phase', () => {
            expect(DEFAULT_STATE.phase).toBe('lobby');
        });

        it('should start at round index 0', () => {
            expect(DEFAULT_STATE.currentRoundIndex).toBe(0);
        });

        it('should have no active team', () => {
            expect(DEFAULT_STATE.activeTeamId).toBeNull();
        });

        it('should have empty final round data', () => {
            expect(DEFAULT_STATE.finalWagers).toEqual({});
            expect(DEFAULT_STATE.finalAnswers).toEqual({});
        });
    });

    describe('Type Validation Helpers', () => {
        it('should validate team structure', () => {
            const validTeam: Team = {
                id: 'team-1',
                name: 'Test Team',
                score: 100,
            };

            expect(validTeam.id).toBeDefined();
            expect(validTeam.name).toBeDefined();
            expect(typeof validTeam.score).toBe('number');
        });

        it('should validate question structure', () => {
            const validQuestion: Question = {
                id: 'q-1',
                question: 'What is 2+2?',
                answer: 'What is 4?',
                points: 100,
                isDailyDouble: false,
                isRevealed: false,
            };

            expect(validQuestion.id).toBeDefined();
            expect(validQuestion.question).toBeDefined();
            expect(validQuestion.answer).toBeDefined();
            expect(typeof validQuestion.points).toBe('number');
            expect(typeof validQuestion.isDailyDouble).toBe('boolean');
            expect(typeof validQuestion.isRevealed).toBe('boolean');
        });

        it('should validate optional imageUrl in question', () => {
            const questionWithImage: Question = {
                id: 'q-1',
                question: 'What is shown?',
                answer: 'What is a cat?',
                points: 200,
                isDailyDouble: false,
                isRevealed: false,
                imageUrl: 'https://example.com/image.jpg',
            };

            expect(questionWithImage.imageUrl).toBeDefined();
        });

        it('should calculate point values correctly', () => {
            const baseValue = 10;
            const multiplier = 2;
            const expectedValues = [20, 40, 60, 80, 100];

            const calculatedValues = DEFAULT_SETTINGS.pointValues.map(
                (v) => v * multiplier
            );

            expect(calculatedValues).toEqual(expectedValues);
        });

        it('should validate game phases', () => {
            const validPhases = [
                'lobby',
                'intro',
                'intro-categories',
                'board',
                'question',
                'daily-double',
                'final-intro',
                'final-category',
                'final-wager',
                'final-question',
                'final-reveal',
                'final-scores',
                'finished',
            ];

            expect(validPhases).toContain(DEFAULT_STATE.phase);
        });
    });
});
