from typing import Callable, List

from django.db import models

from cryptofeed_werks.utils import gettext_lazy as _

# Similar to BigQuery BigNumeric
# https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#decimal_types
NUMERIC_PRECISION = 76  # 76.6
NUMERIC_SCALE = 38


def big_decimal(name: str, validators: List[Callable] = []) -> models.DecimalField:
    return models.DecimalField(
        _(name),
        max_digits=NUMERIC_PRECISION,
        decimal_places=NUMERIC_SCALE,
        validators=validators,
    )


class NameMixin(models.Model):
    name = models.CharField(_("name"), max_length=255, db_index=True)

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

    class Meta:
        abstract = True


class TimestampMixin(models.Model):
    timestamp = models.DateTimeField(_("timestamp"), db_index=True)
    nanoseconds = models.PositiveIntegerField(_("nanoseconds"), db_index=True)

    class Meta:
        abstract = True

from typing import Callable, List

from django.db import models

from cryptofeed_werks.utils import gettext_lazy as _

# Similar to BigQuery BigNumeric
# https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#decimal_types
NUMERIC_PRECISION = 76  # 76.6
NUMERIC_SCALE = 38


def big_decimal(name: str, validators: List[Callable] = []) -> models.DecimalField:
    return models.DecimalField(
        _(name),
        max_digits=NUMERIC_PRECISION,
        decimal_places=NUMERIC_SCALE,
        validators=validators,
    )


class NameMixin(models.Model):
    name = models.CharField(_("name"), max_length=255, db_index=True)

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

    class Meta:
        abstract = True


class TimestampMixin(models.Model):
    timestamp = models.DateTimeField(_("timestamp"), db_index=True)
    nanoseconds = models.PositiveIntegerField(_("nanoseconds"), db_index=True)

    class Meta:
        abstract = True

# Similar to BigQuery BigNumeric # https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#decimal_types # 76.6