import random
from django.core.management.base import BaseCommand
from django.contrib.admin.utils import flatten
from django_seed import Seed
''' from rooms import models as room_models '''
from reviews import models as review_models
from users import models as user_models
from rooms import models as room_models

class Command(BaseCommand):
    help = "This command create review"
    
    def add_arguments(self, parser):
        parser.add_argument(
                "--number",
                default=2,
                type=int,
                help="How many user do you want create"
        )
              
    def handle(self, *args, **options):
        number = options.get("number")
        seeder = Seed.seeder()
        users = user_models.User.objects.all()
        rooms = room_models.Room.objects.all()
        seeder.add_entity(review_models.Review,number,
                          {
                                "accuracy":lambda x:random.randint(0,6),
                                "communication":lambda x:random.randint(0,6),
                                "cleanliness":lambda x:random.randint(0,6),
                                "location":lambda x:random.randint(0,6),
                                "check_in":lambda x:random.randint(0,6),
                                "value":lambda x:random.randint(0,6),
                                "room":lambda x:random.choice(rooms),
                                "user":lambda x:random.choice(users),
                            }
                          )
        created_photos = seeder.execute()
        self.stdout.write(self.style.SUCCESS(f"{number} Reviews created"))
        