import locale
import logging
import os
from os.path import splitext, basename

from django.conf import settings
from django.core.validators import ValidationError, FileExtensionValidator
from django.db import models
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import gettext_lazy as _


logger = logging.getLogger("blackboard")


class JobPosting(models.Model):
    company_name = models.CharField(verbose_name="Firmenname", max_length=128)
    job_name = models.CharField(verbose_name="Berufsbezeichnung", max_length=128)

    salary = models.DecimalField(
        verbose_name="Gehalt",
        max_digits=6,
        decimal_places=1,
    )
    number_of_hours = models.DecimalField(
        default=40,
        verbose_name="Stundenanzahl",
        max_digits=3,
        decimal_places=1,
    )

    pdf_location = models.FileField(
        verbose_name="Stellenausschreibung",
        upload_to="uploads/blackboard/pdf/",
        validators=[FileExtensionValidator(["pdf"])],
    )

    publish_date = models.DateField(
        verbose_name="Veröffentlichung", default=timezone.now
    )

    all_job_postings = models.Manager()

    class Meta:
        verbose_name = "Stellenausschreibung"
        verbose_name_plural = "Stellenausschreibungen"

    def __str__(self):
        return str(self.publish_date) + "_" + self.company_name + "_" + self.job_name

    def get_absolute_url(self):
        return reverse("blackboard")
