from django.db import models
from django.conf import settings

class AnsibleJob(models.Model):
    """Ansible 작업 관리 모델"""
    STATUS_CHOICES = [
        ('PENDING', 'Pending'),
        ('RUNNING', 'Running'),
        ('SUCCESS', 'Success'),
        ('FAILED', 'Failed'),
    ]

    name = models.CharField(max_length=200)
    playbook_content = models.TextField(blank=True, null=True) # Ansible Playbook YAML 내용
    inventory_content = models.TextField(blank=True, null=True) # Ansible Inventory 내용
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='PENDING')
    result = models.TextField(blank=True, null=True)
    owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)

    def __str__(self):
        return self.name