/**
 * 抽奖功能测试
 */
import { describe, it, expect, beforeEach } from 'vitest';
import { adminService } from '../services/admin.service';
import { PRIZE_CONFIG } from '@gala/shared/types';

describe('抽奖功能测试', () => {
  beforeEach(async () => {
    // 重置抽奖状态
    await adminService.setPhase('lottery');
    await adminService.controlLottery('reset');
  });

  describe('抽奖控制', () => {
    it('应该能开始银河阶段', async () => {
      const result = await adminService.controlLottery('start_galaxy');
      expect(result.success).toBe(true);
    });

    it('应该能从银河阶段进入风暴阶段', async () => {
      await adminService.controlLottery('start_galaxy');
      const result = await adminService.controlLottery('start_storm');
      expect(result.success).toBe(true);
    });
  });

  describe('奖项配置', () => {
    it('应该有4轮抽奖配置', () => {
      expect(PRIZE_CONFIG).toHaveLength(4);
    });

    it('第四轮应该是马年限定', () => {
      const round4 = PRIZE_CONFIG[3];
      expect(round4.zodiacFilter).toBe('horse');
    });
  });

  describe('中奖者抽取', () => {
    it('应该能抽取中奖者', async () => {
      await adminService.controlLottery('start_galaxy');
      await adminService.controlLottery('start_storm');
      const result = await adminService.controlLottery('stop_reveal');
      expect(result.success).toBe(true);
      expect(result.data?.winners).toBeDefined();
      expect(Array.isArray(result.data?.winners)).toBe(true);
    });

    it('中奖者数量应该大于0', async () => {
      await adminService.controlLottery('start_galaxy');
      await adminService.controlLottery('start_storm');
      const result = await adminService.controlLottery('stop_reveal');
      // 测试环境使用demo数据(3人)，实际环境会根据配置抽取
      expect(result.data?.winners?.length).toBeGreaterThan(0);
    });

    it('中奖者应该包含必要信息', async () => {
      await adminService.controlLottery('start_galaxy');
      await adminService.controlLottery('start_storm');
      const result = await adminService.controlLottery('stop_reveal');
      const winner = result.data?.winners?.[0];
      expect(winner).toHaveProperty('id');
      expect(winner).toHaveProperty('name');
      expect(winner).toHaveProperty('department');
    });
  });
});
