"""种子：俱乐部工单提现拦截开关。默认仅 lxs 打开。"""
from django.core.management.base import BaseCommand

from gongdan.services import ensure_club_gongdan_config


class Command(BaseCommand):
    help = '初始化俱乐部工单配置（complaint_withdraw_block）'

    def add_arguments(self, parser):
        parser.add_argument('--club-id', default='lxs', help='俱乐部 ID，默认 lxs')
        parser.add_argument('--enable', action='store_true', default=True, help='打开提现拦截')
        parser.add_argument('--disable', action='store_true', help='关闭提现拦截')

    def handle(self, *args, **options):
        club_id = (options.get('club_id') or 'lxs').strip()
        enable = not options.get('disable')
        row = ensure_club_gongdan_config(club_id, withdraw_block=enable)
        if row.complaint_withdraw_block != enable:
            row.complaint_withdraw_block = enable
            row.save(update_fields=['complaint_withdraw_block', 'UpdateTime'])
        self.stdout.write(self.style.SUCCESS(
            f'club={club_id} complaint_withdraw_block={row.complaint_withdraw_block}'
        ))
