from django.core.management.base import BaseCommand
from django.utils import timezone
from property.models import Property  # <-- change 'properties' to your app name if needed
from users.models import Agent
from django.contrib.auth import get_user_model
import random

class Command(BaseCommand):
    help = 'Seed 20 Property objects for user_id=1, post_type=rent, property_type=home'

    def handle(self, *args, **kwargs):
        User = get_user_model()
        try:
            user = User.objects.get(id=1)
        except User.DoesNotExist:
            self.stdout.write(self.style.ERROR('User with id=1 does not exist.'))
            return

        agents = list(Agent.objects.all())

        for i in range(20):
            prop = Property.objects.create(
                post_type='rent',
                property_type='home',
                property_status='available',
                available_from=timezone.now().date(),
                bedrooms=random.randint(1, 5),
                bathrooms=random.randint(1, 3),
                area=random.uniform(800, 3500),
                area_unit=random.choice(['sqft', 'sqm']),
                description=f"Seeded property {i+1} for demo purposes.",
                apartment_no=str(random.randint(100, 500)),
                area_address=f"Area {random.randint(1, 10)}",
                house_no=f"{random.randint(10, 99)}A",
                street=f"Street {random.randint(1, 20)}",
                city="Dhaka",
                state="Dhaka",
                country="Bangladesh",
                zip_code="1207",
                latitude=23.7391665,
                longitude=90.3756501,
                floor_no=random.randint(1, 10),
                built_year=random.randint(2005, 2023),
                garages_count=random.randint(0, 2),
                garage_size=random.uniform(0, 120),
                price=random.randint(50000, 150000),
                price_term=random.choice([c[0] for c in Property.PRICE_TERM_CHOICES]),
                currency='USD',
                contact_details_hidden=random.choice([True, False]),
                hide_address=random.choice([True, False]),
                allow_direct_chat=True,
                posted_by=user,
                agent=random.choice(agents) if agents else None
            )
            self.stdout.write(self.style.SUCCESS(f'Created property: {prop.property_id}'))

        self.stdout.write(self.style.SUCCESS('Successfully seeded 20 properties for user_id=1 (all rent/home)!'))
