from django.db import models


class EsCache(models.Model):
    id = models.BigAutoField(primary_key=True)
    cache_key = models.TextField(unique=True)
    data = models.JSONField(null=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        db_table = "es_cache"

    def __str__(self):
        return self.cache_key
    
    @staticmethod
    def get_multiple_cache(params):
        return dict(
            EsCache.objects.filter(cache_key__in=params).values_list("cache_key", "data", "updated_at")
        )
