from django.db import models
from django.contrib.auth.models import AbstractUser
from PIL import Image
from phonenumber_field.modelfields import PhoneNumberField

class User(AbstractUser):
	CREATOR = 'CREATOR'
	SUBSCRIBER = 'SUBSCRIBER'
	ROLE_CHOICES = (
		(CREATOR, 'Creator'),
		(SUBSCRIBER, 'Subscriber'),
	)
	profile_photo = models.ImageField(upload_to='authentication/images/', null=True, blank=True)
	phone_number = PhoneNumberField()
	address = models.TextField()
	role = models.CharField(max_length=30, choices=ROLE_CHOICES, blank=True)
	IMAGE_MAX_SIZE = (800,800)
	def resize_image(self):
		image = Image.open(self.image)
		image.thumbnail(self.IMAGE_MAX_SIZE)
		image.save(self.image.path)
	def save(self,*args, **kwargs):
		super().save(*args, **kwargs)
		self.resize_image
class Addresse(models.Model):
	addresse = models.TextField()
	user = models.ForeignKey(User, on_delete=models.CASCADE)

class Phone(models.Model):
	phone = PhoneNumberField()
	user = models.ForeignKey(User, on_delete=models.CASCADE)