vars: {
  d2-config: {
    layout-engine: elk
    theme-id: 101
  }
}

external: {
    scaleway: {
        s3
    }

    restic: {
        icon: https://cdn.jsdelivr.net/gh/selfhst/icons/webp/restic.webp
    }
}

classes: {
    zero_grid: {
        grid-columns: 3
        grid-gap: 0
    }
    monitored: {
        style: {
            fill: "#1E9025"
        }
    }
    backup: {
        style: {
            fill: "#0f0"
        }
    }
}

{% for host in hosts %}
{{ host.key }}
{% endfor %}{# host #}

{% for svc in svcs %}
{{ svc.key }}: {
    label: {{ svc.label }}
    label.near: top-left
    icon: {{ svc.icon }}
    icon.near: top-right
}

{% for backup in svc.backup or [] %}
{{ svc.key }}.'{{ backup.name }}'.class: backup
{% endfor %}

{% if svc.monitoring %}
{{ svc.key }}.monitored.class: monitored
{% endif %}

{% if svc.database %}
{{ svc.key }} -> {{ db_key }}: {
    style.stroke: "#336791"
}
{{ db_subkey }}.{{ svc.name }}
{% endif %}

{% if svc.auth %}
{{ svc.key }} -> {{ auth_key }}: {
    style.stroke: "#FD4B2D"
}
{{ auth_subkey }}.{{ svc.name }}
{% endif %}

{% if svc.s3 %}
{{ svc.key }} -> external.scaleway.s3: {
    style: {
        stroke: "#110B1E"
        stroke-dash: 3
    }
}
external.scaleway.s3.{{ svc.name }}
{% endif %}

{% if svc.mail %}
{{ svc.key }} -> {{ mail_key }}: {
    style.stroke: "#C9B81F"
}
{{ mail_subkey }}.{{ svc.name }}
{% endif %}

{% endfor %}{# svc #}

{% for svc in grid_svcs %}
{{ svc }}.class: zero_grid
{% endfor %}