from django.core.management.base import BaseCommand
from django.test.utils import get_runner
from django.conf import settings


class Command(BaseCommand):
    help = 'Run YBP (Yellow/Black Path) view tests to verify correct classification of good and bad gods'

    def add_arguments(self, parser):
        parser.add_argument(
            '--verbose',
            action='store_true',
            help='Verbose output',
        )

    def handle(self, *args, **options):
        """Run the YBP view tests."""
        
        self.stdout.write(
            self.style.SUCCESS('Running YBP (Yellow/Black Path) view tests...')
        )
        
        # Get the test runner
        TestRunner = get_runner(settings)
        test_runner = TestRunner(verbosity=2 if options['verbose'] else 1)
        
        # Run the specific test suite
        failures = test_runner.run_tests(['tongshu.tests.TongshuYBPViewsTestCase'])
        
        if failures:
            self.stdout.write(
                self.style.ERROR(f'Tests failed! {failures} failure(s)')
            )
            return
        
        self.stdout.write(
            self.style.SUCCESS('✅ All YBP view tests passed!')
        )
        self.stdout.write('')
        self.stdout.write('These tests verify that:')
        self.stdout.write('• Good gods (黄道): 青龙, 明堂, 金匮, 天德, 玉堂, 司命 → classified as "good"')
        self.stdout.write('• Bad gods (黑道): 天刑, 朱雀, 白虎, 天牢, 玄武, 勾陈 → classified as "bad"')
        self.stdout.write('• View functions return consistent YBP data')
        self.stdout.write('• Month view template receives properly classified data') 