from django.core.management.base import BaseCommand
import json
from iching.utils.numberpower import NumberPower
from datetime import datetime, timedelta, timezone

class Command(BaseCommand):
    help = 'Test the NumberPower class'

    def add_arguments(self, parser):
        parser.add_argument('--method', type=str)
        parser.add_argument('--dob', type=str)
        parser.add_argument('--dobtime', type=str)
        parser.add_argument('--twin', type=int, default=0)
        parser.add_argument('--fdob', type=str, default=None)
        parser.add_argument('--mdob', type=str, default=None)

    def handle(self, *args, **options):
        method_name = "_calc_" + options.get('method')
        method = getattr(self, method_name, None)

        if method is None:
            self.stderr.write(f"Method '{method_name}' not found.")
            return

        method(options)
    
    def _calc_formatDOB(self, options):
        result = NumberPower.formatDOB(options)
        self.stdout.write(f"Testing for formatDOB")
        self.stdout.write(f"{result}")
    
    def _calc_triangle(self, options):
        dob = options.get('dob', '0000-00-00')
        date = datetime.strptime(dob, '%Y-%m-%d')
        date = date.strftime('%d%m%Y')
        result = NumberPower.triangle(date)
        self.stdout.write(f"Testing for triangle for {date}")
        self.stdout.write(f"{result}")

    def _calc_calculate(self, options):
        result = NumberPower.calculate(options)
        self.stdout.write(f"Testing for calculate")
        self.stdout.write(f"{result}")