from datetime import timedelta from django.contrib.auth import get_user_model from django.core.management.base import BaseCommand from django.utils import timezone from apps.bookings.models import Booking, BookingStatus from apps.payments.models import Payment, PaymentProvider, PaymentStatus from apps.salons.models import Review, Salon, SalonPhoto, Service, StaffProfile class Command(BaseCommand): help = "Seed demo data for local development" def handle(self, *args, **options): User = get_user_model() admin, _ = User.objects.get_or_create( email="admin@example.com", defaults={"role": "admin", "is_staff": True, "is_superuser": True}, ) if not admin.has_usable_password(): admin.set_password("Admin123!") admin.save(update_fields=["password"]) manager, _ = User.objects.get_or_create( email="manager@example.com", defaults={"role": "manager", "first_name": "Rania", "last_name": "Mansour"}, ) if not manager.has_usable_password(): manager.set_password("Manager123!") manager.save(update_fields=["password"]) staff_user, _ = User.objects.get_or_create( email="stylist@example.com", defaults={"role": "staff", "first_name": "Lina", "last_name": "Hassan"}, ) if not staff_user.has_usable_password(): staff_user.set_password("Staff123!") staff_user.save(update_fields=["password"]) customer, _ = User.objects.get_or_create( email="customer@example.com", defaults={"role": "customer", "first_name": "Yara", "last_name": "Saleh"}, ) if not customer.has_usable_password(): customer.set_password("Customer123!") customer.save(update_fields=["password"]) salon, _ = Salon.objects.get_or_create( owner=manager, name="Luxe Riyadh Studio", defaults={ "description": "Premium styling and beauty services in the heart of Riyadh.", "address": "Olaya Street", "city": "Riyadh", "phone_number": "+966500000000", "email": "hello@luxeriayadh.example", "website": "https://luxeriayadh.example", }, ) SalonPhoto.objects.get_or_create( salon=salon, image_url="https://images.unsplash.com/photo-1522335789203-aabd1fc54bc9", defaults={"alt_text": "Salon interior", "sort_order": 1}, ) service_blowout, _ = Service.objects.get_or_create( salon=salon, name="Signature Blowout", defaults={ "description": "45-minute styling session with wash and blowdry.", "duration_minutes": 45, "price_amount": 180, "currency": "SAR", }, ) service_color, _ = Service.objects.get_or_create( salon=salon, name="Color Refresh", defaults={ "description": "Full color refresh with toning and gloss.", "duration_minutes": 90, "price_amount": 420, "currency": "SAR", }, ) staff_profile, _ = StaffProfile.objects.get_or_create( user=staff_user, salon=salon, defaults={"title": "Senior Stylist", "bio": "Specialist in modern cuts and color."}, ) Review.objects.get_or_create( salon=salon, customer=customer, defaults={"rating": 5, "comment": "Loved the service and attention to detail."}, ) salon.rating_avg = 5 salon.rating_count = 1 salon.save(update_fields=["rating_avg", "rating_count"]) start_time = timezone.now() + timedelta(days=1) end_time = start_time + timedelta(minutes=service_blowout.duration_minutes) booking, _ = Booking.objects.get_or_create( salon=salon, customer=customer, service=service_blowout, staff=staff_profile, start_time=start_time, end_time=end_time, defaults={ "status": BookingStatus.CONFIRMED, "price_amount": service_blowout.price_amount, "currency": service_blowout.currency, "notes": "Prefers natural volume.", }, ) Payment.objects.get_or_create( booking=booking, provider=PaymentProvider.MOYASAR, defaults={ "status": PaymentStatus.CREATED, "amount": booking.price_amount, "currency": booking.currency, "external_id": "", "metadata": {"note": "Demo payment record"}, }, ) self.stdout.write(self.style.SUCCESS("Demo data seeded."))