from django.db import models
from django.contrib.auth.models import User
from ckeditor_uploader.fields import RichTextUploadingField
from django.utils.translation import gettext as _
# Create your models here.

default_image = "../static/assets/images/client-1.png"

class DatosExtraUser(models.Model):
    usuario = models.OneToOneField(User, on_delete=models.CASCADE)
    imagen = models.ImageField(upload_to="static/assets/images", default=default_image)
    direccion = models.CharField(max_length=240, blank=True, null=True)
    correo = models.CharField(max_length=30, blank=True, null=True)
    def __str__(self):
        return self.usuario.username
    
    def toJson(self):
        json = {
            'usuario': self.usuario.username,
            'imagen' : self.imagen.url,
            'direccion' : self.direccion,
            'correo' : self.correo,
        }
        return json

class PorfolioInfo(models.Model):
    usuario = models.ForeignKey(User,on_delete=models.CASCADE)
    active = models.BooleanField(default=False)
    imagen_linkedin = models.ImageField(upload_to="static/assets/images/", default=default_image)
    imagen_github = models.ImageField(upload_to="static/assets/images/", default=default_image)
    imagen_mail = models.ImageField(upload_to="static/assets/images/", default=default_image) 
    url_linkedin = models.CharField(max_length=240, blank=True, null=True)
    url_git_hub = models.CharField(max_length=240, blank=True, null=True)
    about_me = RichTextUploadingField(blank=True, null=True)
    def __str__(self):
        return self.usuario.username
    def toJson(self):
        json = {
            'usuario': self.usuario.username,
            'active' : self.active,
            'imagen_linkedin' : self.imagen_linkedin.url,
            'imagen_github' : self.imagen_github.url,
            'url_linkedin' : self.url_linkedin,
            'url_git_hub' : self.url_git_hub,
            'about_me': self.about_me
            }
        return json
class Experiencia(models.Model):
    usuario = models.ForeignKey(User, on_delete=models.CASCADE)
    fecha_ini = models.DateTimeField(_("Fecha de inicio"), auto_now=False, auto_now_add=False, null=True, blank=True)
    fecha_fin = models.DateTimeField(_("Fecha de fin"), auto_now=False, auto_now_add=False, null=True, blank=True)
    actual = models.BooleanField(default=False, null=True, blank=True)
    nombre = models.CharField(max_length=240, null=True, blank=True)
    empresa = models.CharField(max_length=240,  null=True, blank=True)
    def __str__(self):
        return self.nombre
    def toJson(self):
        json = {
            'usuario': self.usuario.username,
            'fecha_ini' : self.fecha_ini,
            'fecha_fin' : self.fecha_fin,
            'actual' : self.actual,
            'nombre' : self.nombre,
            'empresa' : self.empresa,
        }
class Skills (models.Model):
    usuario = models.ForeignKey(User, on_delete=models.CASCADE)
    imagen = models.ImageField(upload_to="static/assets/images/",default=default_image)
    name = models.CharField(max_length=240, null=True, blank=True)
    year = models.IntegerField(null=True, blank=True)
    def __str__(self):
        return self.name
    def toJson(self):
        json = {
            'usuario': self.usuario.username,
            'imagen' : self.imagen.url,
            'name' : self.name,
            'year' : self.year,
        }
        return json
class Projects (models.Model):
    usuario = models.ForeignKey(User, on_delete=models.CASCADE)
    imagen = models.ImageField(upload_to="static/assets/images/",default=default_image)
    name = models.CharField(max_length=240, null=True, blank=True)
    year = models.IntegerField(null=True, blank=True)
    def toJson(self):
        json = {
            'usuario': self.usuario.username,
            'imagen' : self.imagen.url,
            'name' : self.name,
            'year' : self.year,
        }
        return json

class ConfiguracionCSS(models.Model):
    usuario = models.ForeignKey(User, on_delete=models.CASCADE)
    root_primary_color = models.CharField(max_length=50, default='#fb4444')
    def toJson(self):
        json = {
            'root_primary_color' : self.root_primary_color,
        }
        return json