from __future__ import annotations

from typing import ClassVar

from django.db import models
from django.utils.translation import gettext_lazy as _

from simorgh.core.models import TenantScopedModel, UUIDModel


class WorkLocation(UUIDModel, TenantScopedModel):
    """Physical or remote work location."""

    organization_node = models.ForeignKey(
        "organizations.OrganizationNode",
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
        related_name="+",
        verbose_name=_("organization node"),
    )

    code = models.CharField(_("code"), max_length=40)
    name = models.CharField(_("name"), max_length=200)
    address_line1 = models.CharField(_("address line 1"), max_length=200, blank=True)
    address_line2 = models.CharField(_("address line 2"), max_length=200, blank=True)
    city = models.CharField(_("city"), max_length=100, blank=True)
    state = models.CharField(_("state/province"), max_length=100, blank=True)
    postal_code = models.CharField(_("postal code"), max_length=20, blank=True)
    country = models.CharField(_("country"), max_length=2, blank=True)
    timezone = models.CharField(_("timezone"), max_length=50, blank=True)
    is_remote = models.BooleanField(_("remote"), default=False)
    is_active = models.BooleanField(_("active"), default=True)

    class Meta(TenantScopedModel.Meta):
        db_table = "hr_work_location"
        verbose_name = _("Work Location")
        verbose_name_plural = _("Work Locations")
        constraints: ClassVar[list] = [
            models.UniqueConstraint(
                fields=["tenant", "code"],
                name="hr_worklocation_unique_tenant_code",
            )
        ]
        ordering = ["name"]

    def __str__(self) -> str:
        return self.name
