
from django.core.management.base import BaseCommand
from expenditure.models import ExpenseCategory

class Command(BaseCommand):
    help = 'Set up initial expense categories'

    def handle(self, *args, **options):
        categories = [
            {
                'name': 'Travel & Transportation',
                'description': 'Business travel, taxi fares, fuel, vehicle maintenance'
            },
            {
                'name': 'Office Supplies',
                'description': 'Stationery, equipment, software licenses'
            },
            {
                'name': 'Meals & Entertainment',
                'description': 'Business meals, client entertainment, team lunches'
            },
            {
                'name': 'Training & Development',
                'description': 'Training courses, conferences, certifications'
            },
            {
                'name': 'Marketing & Advertising',
                'description': 'Promotional materials, advertising campaigns, branding'
            },
            {
                'name': 'Utilities & Communications',
                'description': 'Internet, phone bills, utility payments'
            },
            {
                'name': 'Equipment & Tools',
                'description': 'Technical equipment, tools, hardware purchases'
            },
            {
                'name': 'Professional Services',
                'description': 'Consulting, legal services, accounting'
            },
            {
                'name': 'Maintenance & Repairs',
                'description': 'Equipment repairs, facility maintenance'
            },
            {
                'name': 'Miscellaneous',
                'description': 'Other business-related expenses'
            }
        ]

        created_count = 0
        for category_data in categories:
            category, created = ExpenseCategory.objects.get_or_create(
                name=category_data['name'],
                defaults={'description': category_data['description']}
            )
            if created:
                created_count += 1
                self.stdout.write(
                    self.style.SUCCESS(f'Created expense category: {category.name}')
                )
            else:
                self.stdout.write(
                    self.style.WARNING(f'Expense category already exists: {category.name}')
                )

        self.stdout.write(
            self.style.SUCCESS(
                f'Successfully set up {created_count} new expense categories!'
            )
        )
