from django.core.management.base import BaseCommand
import json
from iching.utils.bzshagod import tian_yi_at, check_tian_de
from iching.utils.bz import gGodstem, gEarthstem

class Command(BaseCommand):
    help = 'Test the got_at method'

    def add_arguments(self, parser):
        parser.add_argument('--god', type=int, help='Day pillar god stem index (0-9)', default=None)
        parser.add_argument('--earth', type=int, help='Earth branch to check (0-11)', default=None)

    def handle(self, *args, **options):
        self._tian_yi_at(options)
    
    def _tian_yi_at(self, options):
        if options['god'] is not None:
            god_index = options['god']
            result = tian_yi_at(god_index)
            self.stdout.write(f"Testing for 天乙贵人")
            for tian_yi_type in result:
                earth = result[tian_yi_type]
                type_str = "阳贵人" if tian_yi_type == 1 else "阴贵人"
                self.stdout.write(f"{type_str}: {gEarthstem[earth]}")