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


class UserProfileInfo(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)

    portfolio_site = models.URLField(blank=True)

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


class UrlType(models.Model):
    name = models.CharField(max_length=160)

    class Meta:
        db_table = "vulnerability_app_url_type"

    def __str__(self):
        return f"URL type: {self.name}"


class Url(models.Model):
    path = models.URLField(blank=True)
    accessed_on = models.DateField()
    ip = models.CharField(max_length=160)
    url_type = models.ForeignKey(UrlType,
                                 to_field="id",
                                 on_delete=models.CASCADE,
                                 )

    class Meta:
        db_table = "vulnerability_app_url"

    def __str__(self):
        return f"URL: {self.path}, ACCESSED_ON: {self.accessed_on}, IP: {self.ip}, URL TYPE: {self.url_type.name}"


class SafeDomain(models.Model):
    domain = models.CharField(max_length=160)
    company = models.CharField(max_length=160)

    class Meta:
        db_table = "vulnerability_app_safe_domain"

    def __str__(self):
        return f"DOMAIN: {self.domain}, COMPANY: {self.company}"
