from django.db import models
from django.contrib.auth.models import User


class UserModel(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='token_of')
    refresh_token = models.CharField(max_length=120, null=True, blank=True)
    gmb_account_id = models.CharField(max_length=30, null=True, blank=True)

    def __str__(self):
        return self.user.username


class Location(models.Model):
    location_id = models.CharField(max_length=50, primary_key=True)
    care_name = models.CharField(max_length=50, null=True)
    location_name = models.CharField(max_length=120)
    website_url = models.URLField()
    display_name = models.CharField(max_length=120)
    average_rating = models.FloatField(null=True, blank=True)
    total_review = models.IntegerField(null=True, blank=True)
    total_review_DB = models.IntegerField(null=True, blank=True)
    owner = models.ForeignKey(User, on_delete=models.CASCADE, null=True)

    def __str__(self):
        return self.care_name if self.care_name else self.location_name
