from django.db import models
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager


class MyAccountManager(BaseUserManager):
	def create_user(self, email, username, password=None):
		if not email:
			raise ValueError('Users must have an email address')
		if not username:
			raise ValueError('Users must have a username')

		user = self.model(
			email=self.normalize_email(email),
			username=username,
		)

		user.set_password(password)
		user.save(using=self._db)
		return user

	def create_superuser(self, email, username, password):
		user = self.create_user(
			email=self.normalize_email(email),
			password=password,
			username=username,
		)
		user.is_admin = True
		user.is_staff = True
		user.is_superuser = True
		user.save(using=self._db)
		return user


class UserVendor(AbstractBaseUser):
	email = models.EmailField(verbose_name='email address',max_length=255,unique=True)
	contact = models.IntegerField(null=True, blank=True)
	username = models.CharField(max_length=30)
	location = models.CharField(max_length=30)
	profession = models.CharField(max_length=30)
	experience = models.CharField(max_length=30)
	verified_id = models.CharField(max_length=255)
	date_joined	= models.DateTimeField(verbose_name='date joined', auto_now_add=True)
	is_active   = models.BooleanField(default=True)
	is_admin    = models.BooleanField(default=False)
	is_staff    = models.BooleanField(default=False)
	image = models.ImageField(default='profile1.png' ,upload_to='profiles/images/', null=True, blank=True)
	# notice the absence of a "Password field", that is built in.
	objects = MyAccountManager()

	USERNAME_FIELD = 'email'
	REQUIRED_FIELDS = ['username'] # Email & Password are required by default.

	def __str__(self):
		return self.email

	# For checking permissions. to keep it simple all admin have ALL permissons
	def has_perm(self, perm, obj=None):
		return self.is_admin

	# Does this user have permission to view this app? (ALWAYS YES FOR SIMPLICITY)
	def has_module_perms(self, app_label):
		return True



class Client(AbstractBaseUser):
	email = models.EmailField(verbose_name='email address',max_length=255,unique=True)
	contact = models.IntegerField(null=True, blank=True)
	username = models.CharField(max_length=30)
	location = models.CharField(max_length=30)
	date_joined	= models.DateTimeField(verbose_name='date joined', auto_now_add=True)
	is_active   = models.BooleanField(default=True)
	is_admin    = models.BooleanField(default=False)
	is_staff    = models.BooleanField(default=False)
	# notice the absence of a "Password field", that is built in.
	objects = MyAccountManager()

	USERNAME_FIELD = 'email'
	REQUIRED_FIELDS = ['username'] # Email & Password are required by default.

	def __str__(self):
		return self.email

	# For checking permissions. to keep it simple all admin have ALL permissons
	def has_perm(self, perm, obj=None):
		return self.is_admin

	# Does this user have permission to view this app? (ALWAYS YES FOR SIMPLICITY)
	def has_module_perms(self, app_label):
		return True

[((833, 909), 'django.db.models.EmailField', 'models.EmailField', ([], {'verbose_name': '"""email address"""', 'max_length': '(255)', 'unique': '(True)'}), "(verbose_name='email address', max_length=255, unique=True)\n", (850, 909), False, 'from django.db import models\n'), ((919, 961), 'django.db.models.IntegerField', 'models.IntegerField', ([], {'null': '(True)', 'blank': '(True)'}), '(null=True, blank=True)\n', (938, 961), False, 'from django.db import models\n'), ((974, 1005), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(30)'}), '(max_length=30)\n', (990, 1005), False, 'from django.db import models\n'), ((1018, 1049), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(30)'}), '(max_length=30)\n', (1034, 1049), False, 'from django.db import models\n'), ((1064, 1095), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(30)'}), '(max_length=30)\n', (1080, 1095), False, 'from django.db import models\n'), ((1110, 1141), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(30)'}), '(max_length=30)\n', (1126, 1141), False, 'from django.db import models\n'), ((1157, 1189), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(255)'}), '(max_length=255)\n', (1173, 1189), False, 'from django.db import models\n'), ((1205, 1272), 'django.db.models.DateTimeField', 'models.DateTimeField', ([], {'verbose_name': '"""date joined"""', 'auto_now_add': '(True)'}), "(verbose_name='date joined', auto_now_add=True)\n", (1225, 1272), False, 'from django.db import models\n'), ((1288, 1321), 'django.db.models.BooleanField', 'models.BooleanField', ([], {'default': '(True)'}), '(default=True)\n', (1307, 1321), False, 'from django.db import models\n'), ((1337, 1371), 'django.db.models.BooleanField', 'models.BooleanField', ([], {'default': '(False)'}), '(default=False)\n', (1356, 1371), False, 'from django.db import models\n'), ((1387, 1421), 'django.db.models.BooleanField', 'models.BooleanField', ([], {'default': '(False)'}), '(default=False)\n', (1406, 1421), False, 'from django.db import models\n'), ((1431, 1529), 'django.db.models.ImageField', 'models.ImageField', ([], {'default': '"""profile1.png"""', 'upload_to': '"""profiles/images/"""', 'null': '(True)', 'blank': '(True)'}), "(default='profile1.png', upload_to='profiles/images/',\n    null=True, blank=True)\n", (1448, 1529), False, 'from django.db import models\n'), ((2080, 2156), 'django.db.models.EmailField', 'models.EmailField', ([], {'verbose_name': '"""email address"""', 'max_length': '(255)', 'unique': '(True)'}), "(verbose_name='email address', max_length=255, unique=True)\n", (2097, 2156), False, 'from django.db import models\n'), ((2166, 2208), 'django.db.models.IntegerField', 'models.IntegerField', ([], {'null': '(True)', 'blank': '(True)'}), '(null=True, blank=True)\n', (2185, 2208), False, 'from django.db import models\n'), ((2221, 2252), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(30)'}), '(max_length=30)\n', (2237, 2252), False, 'from django.db import models\n'), ((2265, 2296), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(30)'}), '(max_length=30)\n', (2281, 2296), False, 'from django.db import models\n'), ((2312, 2379), 'django.db.models.DateTimeField', 'models.DateTimeField', ([], {'verbose_name': '"""date joined"""', 'auto_now_add': '(True)'}), "(verbose_name='date joined', auto_now_add=True)\n", (2332, 2379), False, 'from django.db import models\n'), ((2395, 2428), 'django.db.models.BooleanField', 'models.BooleanField', ([], {'default': '(True)'}), '(default=True)\n', (2414, 2428), False, 'from django.db import models\n'), ((2444, 2478), 'django.db.models.BooleanField', 'models.BooleanField', ([], {'default': '(False)'}), '(default=False)\n', (2463, 2478), False, 'from django.db import models\n'), ((2494, 2528), 'django.db.models.BooleanField', 'models.BooleanField', ([], {'default': '(False)'}), '(default=False)\n', (2513, 2528), False, 'from django.db import models\n')]