from django.db import models


from django.db import models
from django.contrib.auth.models import AbstractUser

class PMSConfiguration(models.Model):
    name = models.CharField(max_length=255, verbose_name="Название PMS")
    url = models.URLField(verbose_name="URL API")
    token = models.CharField(max_length=255, blank=True, null=True, verbose_name="Токен")
    public_key = models.CharField(max_length=255, blank=True, null=True, verbose_name="Публичный ключ")
    private_key = models.CharField(max_length=255, blank=True, null=True, verbose_name="Приватный ключ")
    username = models.CharField(max_length=255, blank=True, null=True, verbose_name="Логин")
    password = models.CharField(max_length=255, blank=True, null=True, verbose_name="Пароль")
    plugin_name = models.CharField(max_length=255, blank=True, null=True, verbose_name="Плагин")
    created_at = models.DateTimeField(auto_now_add=True, verbose_name="Дата создания")


    def __str__(self):
        return self.name

    class Meta:
        verbose_name = "PMS система"
        verbose_name_plural = "PMS системы"



class PMSIntegrationLog(models.Model):
    hotel = models.ForeignKey(
        'hotels.Hotel',  # Используем строковую ссылку
        on_delete=models.CASCADE,
        verbose_name="Отель"
    )
    checked_at = models.DateTimeField(auto_now_add=True, verbose_name="Время проверки")
    status = models.CharField(max_length=50, verbose_name="Статус", choices=[('success', 'Успех'), ('error', 'Ошибка')])
    message = models.TextField(verbose_name="Сообщение", blank=True, null=True)

    def __str__(self):
        return f"{self.hotel.name} - {self.status} - {self.checked_at}"

    class Meta:
        verbose_name = "Журнал интеграции PMS"
        verbose_name_plural = "Журналы интеграции PMS"
        indexes = [
            models.Index(fields=['hotel']),
            models.Index(fields=['checked_at']),
            models.Index(fields=['status']),
        ]
