# -*- coding: utf-8 -*-
from __future__ import annotations

from django.db import models
from django.utils.timezone import now
import uuid6


class Model(models.Model):
    id = models.UUIDField(
        primary_key=True,
        null=False,
        default=uuid6.uuid7,
        editable=False,
    )
    account_uuid = models.UUIDField(
        blank=False, null=False, default=None, db_index=True,
    )
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    deleted_at = models.DateTimeField(
        blank=True,
        null=True,
        default=None,
        db_index=True,
        editable=False,
    )

    class Meta:
        abstract = True

    @property
    def is_active(self) -> bool:
        return self.deleted_at is None

    def save(self,
             force_insert=False,
             force_update=False,
             using=None,
             update_fields=None,
             ):
        self.full_clean()
        super().save(
            force_insert=force_insert,
            force_update=force_update,
            using=using,
            update_fields=update_fields,
        )

    def soft_delete(self, save=True) -> None:
        self.deleted_at = now()

        if save is True:
            self.save()
