"""
Django models - Generated from schema.json

DO NOT EDIT MANUALLY - Regenerate from schema.json
"""

from django.db import models


class Status(models.TextChoices):
    PENDING = "pending", "Pending"
    PLANNED = "planned", "Planned"
    BUILDING = "building", "Building"
    DEV = "dev", "Dev"
    LIVE = "live", "Live"
    READY = "ready", "Ready"


class System(models.TextChoices):
    ARTERY = "artery", "Artery"
    ALBUM = "album", "Album"
    WARD = "ward", "Ward"


# === Shared Components ===

class Nest(models.Model):
    """Runtime environment configuration. Shared across artery, ward."""
    name = models.CharField(max_length=255, help_text="Unique identifier")
    slug = models.SlugField(max_length=255, unique=True, help_text="URL-friendly identifier")
    title = models.CharField(max_length=255, help_text="Display title for UI")
    status = models.ForeignKey(Status, on_delete=models.SET_NULL, blank=True, null=True, related_name="nests")
    config_path = models.CharField(max_length=255, blank=True, null=True)

    class Meta:
        db_table = "pawprint_nest"

    def __str__(self):
        return self.title


class Larder(models.Model):
    """Data storage. When generated from Template = 'Book (written)'. Independent in ward/artery."""
    name = models.CharField(max_length=255, help_text="Unique identifier")
    slug = models.SlugField(max_length=255, unique=True, help_text="URL-friendly identifier")
    title = models.CharField(max_length=255, help_text="Display title for UI")
    status = models.ForeignKey(Status, on_delete=models.SET_NULL, blank=True, null=True, related_name="larders")
    source_template = models.CharField(max_length=255, blank=True, null=True, help_text="Template name if generated")
    data_path = models.CharField(max_length=255, blank=True, null=True, help_text="Path to data files")

    class Meta:
        db_table = "pawprint_larder"

    def __str__(self):
        return self.title


# === System-Specific Components ===

class Vein(models.Model):
    """Connector (artery). Single responsibility."""
    name = models.CharField(max_length=255, help_text="Unique identifier")
    slug = models.SlugField(max_length=255, unique=True, help_text="URL-friendly identifier")
    title = models.CharField(max_length=255, help_text="Display title for UI")
    status = models.ForeignKey(Status, on_delete=models.SET_NULL, blank=True, null=True, related_name="veins")
    system = models.CharField(max_length=20, default="artery", editable=False)

    class Meta:
        db_table = "pawprint_vein"

    def __str__(self):
        return self.title


class Template(models.Model):
    """Documentation template (album). Gherkin, BDD patterns."""
    name = models.CharField(max_length=255, help_text="Unique identifier")
    slug = models.SlugField(max_length=255, unique=True, help_text="URL-friendly identifier")
    title = models.CharField(max_length=255, help_text="Display title for UI")
    status = models.ForeignKey(Status, on_delete=models.SET_NULL, blank=True, null=True, related_name="templates")
    template_path = models.CharField(max_length=255, blank=True, null=True, help_text="Path to template files")
    system = models.CharField(max_length=20, default="album", editable=False)

    class Meta:
        db_table = "pawprint_template"

    def __str__(self):
        return self.title


class Tool(models.Model):
    """Execution tool (ward). Test runners, seeders."""
    name = models.CharField(max_length=255, help_text="Unique identifier")
    slug = models.SlugField(max_length=255, unique=True, help_text="URL-friendly identifier")
    title = models.CharField(max_length=255, help_text="Display title for UI")
    status = models.ForeignKey(Status, on_delete=models.SET_NULL, blank=True, null=True, related_name="tools")
    system = models.CharField(max_length=20, default="ward", editable=False)

    class Meta:
        db_table = "pawprint_tool"

    def __str__(self):
        return self.title


class Monitor(models.Model):
    """Service monitor (ward). Health checks, status watchers."""
    name = models.CharField(max_length=255, help_text="Unique identifier")
    slug = models.SlugField(max_length=255, unique=True, help_text="URL-friendly identifier")
    title = models.CharField(max_length=255, help_text="Display title for UI")
    status = models.ForeignKey(Status, on_delete=models.SET_NULL, blank=True, null=True, related_name="monitors")
    system = models.CharField(max_length=20, default="ward", editable=False)

    class Meta:
        db_table = "pawprint_monitor"

    def __str__(self):
        return self.title


class Cabinet(models.Model):
    """Tool cabinet (ward). Contains 0+ tools."""
    name = models.CharField(max_length=255, help_text="Unique identifier")
    slug = models.SlugField(max_length=255, unique=True, help_text="URL-friendly identifier")
    title = models.CharField(max_length=255, help_text="Display title for UI")
    status = models.ForeignKey(Status, on_delete=models.SET_NULL, blank=True, null=True, related_name="cabinets")
    tools = models.ManyToManyField(Tool, blank=True)
    system = models.CharField(max_length=20, default="ward", editable=False)

    class Meta:
        db_table = "pawprint_cabinet"

    def __str__(self):
        return self.title


# === Composed Types ===

class Pulse(models.Model):
    """Composed data flow (artery). Pulse = Vein + Nest + Larder."""
    name = models.CharField(max_length=255, help_text="Unique identifier")
    slug = models.SlugField(max_length=255, unique=True, help_text="URL-friendly identifier")
    title = models.CharField(max_length=255, help_text="Display title for UI")
    status = models.ForeignKey(Status, on_delete=models.SET_NULL, blank=True, null=True, related_name="pulses")
    vein = models.ForeignKey(Vein, on_delete=models.SET_NULL, blank=True, null=True, related_name="pulses")
    nest = models.ForeignKey(Nest, on_delete=models.SET_NULL, blank=True, null=True, related_name="pulses")
    larder = models.ForeignKey(Larder, on_delete=models.SET_NULL, blank=True, null=True, related_name="pulses")
    system = models.CharField(max_length=20, default="artery", editable=False)

    class Meta:
        db_table = "pawprint_pulse"

    def __str__(self):
        return self.title


class Book(models.Model):
    """Composed documentation (album). Book = Template + Larder."""
    name = models.CharField(max_length=255, help_text="Unique identifier")
    slug = models.SlugField(max_length=255, unique=True, help_text="URL-friendly identifier")
    title = models.CharField(max_length=255, help_text="Display title for UI")
    status = models.ForeignKey(Status, on_delete=models.SET_NULL, blank=True, null=True, related_name="books")
    template = models.ForeignKey(Template, on_delete=models.SET_NULL, blank=True, null=True, related_name="books")
    larder = models.ForeignKey(Larder, on_delete=models.SET_NULL, blank=True, null=True, related_name="books")
    output_larder = models.ForeignKey(Larder, on_delete=models.SET_NULL, blank=True, null=True, related_name="books")
    system = models.CharField(max_length=20, default="album", editable=False)

    class Meta:
        db_table = "pawprint_book"

    def __str__(self):
        return self.title


class Table(models.Model):
    """Composed execution bundle (ward). Table = Cabinet + Nest + Larders."""
    name = models.CharField(max_length=255, help_text="Unique identifier")
    slug = models.SlugField(max_length=255, unique=True, help_text="URL-friendly identifier")
    title = models.CharField(max_length=255, help_text="Display title for UI")
    status = models.ForeignKey(Status, on_delete=models.SET_NULL, blank=True, null=True, related_name="tables")
    cabinet = models.ForeignKey(Cabinet, on_delete=models.SET_NULL, blank=True, null=True, related_name="tables")
    nest = models.ForeignKey(Nest, on_delete=models.SET_NULL, blank=True, null=True, related_name="tables")
    larders = models.ManyToManyField(Larder, blank=True)
    system = models.CharField(max_length=20, default="ward", editable=False)

    class Meta:
        db_table = "pawprint_table"

    def __str__(self):
        return self.title

