digraph DataModelSimple {
    rankdir=TB
    compound=true
    splines=ortho
    node [shape=box, style="rounded,filled", fontname="Helvetica", fontsize=10]
    edge [fontname="Helvetica", fontsize=8]
    nodesep=0.3
    ranksep=1.2
    newrank=true

    label="AMAR Mascotas - Data Model Overview"
    labelloc="t"
    fontsize=16
    fontname="Helvetica-Bold"

    // === ROW 1: AUTH (center) ===
    subgraph cluster_auth {
        label="Users & Auth"
        style="rounded,filled"
        fillcolor="#E8F5E9"
        color="#2E7D32"
        auth_user [label="auth.User", fillcolor="#C8E6C9"]
    }

    // === ROW 2: LEFT COLUMN - Pet Owners ===
    subgraph cluster_mascotas {
        label="Pet Owners & Pets"
        style="rounded,filled"
        fillcolor="#E3F2FD"
        color="#1565C0"

        petowner [label="PetOwner", fillcolor="#BBDEFB"]
        pet [label="Pet", fillcolor="#BBDEFB"]
        petvaccine [label="PetVaccine", fillcolor="#90CAF9"]
        petstudy [label="PetStudy", fillcolor="#90CAF9"]
    }

    // === ROW 2: CENTER COLUMN - Veterinarians ===
    subgraph cluster_vets {
        label="Veterinarians"
        style="rounded,filled"
        fillcolor="#FFF3E0"
        color="#E65100"

        veterinarian [label="Veterinarian", fillcolor="#FFE0B2"]
        availability [label="Availability", fillcolor="#FFCC80"]
        unavailability [label="Unavailability", fillcolor="#FFCC80"]
        vet_specialty [label="Vet-Specialty", shape=diamond, fillcolor="#FFB74D"]
        vet_neighborhood [label="Vet-Neighborhood", shape=diamond, fillcolor="#FFB74D"]
    }

    // === ROW 2: RIGHT COLUMN - Services ===
    subgraph cluster_productos {
        label="Services & Pricing"
        style="rounded,filled"
        fillcolor="#F3E5F5"
        color="#7B1FA2"

        grupo [label="Group", fillcolor="#E1BEE7"]
        category [label="Category", fillcolor="#E1BEE7"]
        service [label="Service", fillcolor="#CE93D8"]
        prices [label="Prices", fillcolor="#BA68C8"]
        discounts [label="Discounts", fillcolor="#BA68C8"]
    }

    // === ROW 3: LEFT - Cart ===
    subgraph cluster_cart {
        label="Cart & Checkout"
        style="rounded,filled"
        fillcolor="#E0F7FA"
        color="#00838F"

        cart [label="Cart", fillcolor="#B2EBF2"]
        cartitem [label="CartItem", fillcolor="#80DEEA"]
        cartresumeitem [label="CartResumeItem", fillcolor="#80DEEA"]
        cartpetreason [label="CartPetReason", fillcolor="#80DEEA"]
    }

    // === ROW 3: CENTER - Requests ===
    subgraph cluster_solicitudes {
        label="Service Requests"
        style="rounded,filled"
        fillcolor="#FFEBEE"
        color="#C62828"

        servicerequest [label="ServiceRequest", fillcolor="#FFCDD2"]
        statehistory [label="StateHistory", fillcolor="#EF9A9A"]
        vetasked [label="VeterinarianAsked", fillcolor="#EF9A9A"]
        vetreminder [label="VetReminder", fillcolor="#E57373"]
        payreminder [label="PayReminder", fillcolor="#E57373"]
    }

    // === ROW 3: RIGHT - Visits ===
    subgraph cluster_visits {
        label="Veterinary Visits"
        style="rounded,filled"
        fillcolor="#FFFDE7"
        color="#F9A825"

        vetvisit [label="VetVisit", fillcolor="#FFF9C4"]
        vetvisitreport [label="VetVisitReport", fillcolor="#FFF59D"]
        vetvisitfollowup [label="FollowUp", fillcolor="#FFF176"]
        vetvisitpetreason [label="VisitPetReason", fillcolor="#FFF176"]
        visit_pets [label="Visit-Pets", shape=diamond, fillcolor="#FFEE58"]
        receipt [label="Receipt\n(AFIP)", fillcolor="#F8BBD9"]
    }

    // === ROW 4: REFERENCE DATA (bottom, full width) ===
    subgraph cluster_reference {
        label="Reference Data"
        style="rounded,filled"
        fillcolor="#ECEFF1"
        color="#455A64"

        subgraph {
            rank=same
            specialty [label="Specialty", fillcolor="#CFD8DC"]
            neighborhood [label="Neighborhood", fillcolor="#CFD8DC"]
            province [label="Province", fillcolor="#CFD8DC"]
            locality [label="Locality", fillcolor="#CFD8DC"]
            petbreed [label="PetBreed", fillcolor="#CFD8DC"]
            vaccine [label="Vaccine", fillcolor="#CFD8DC"]
        }
        subgraph {
            rank=same
            study [label="Study", fillcolor="#CFD8DC"]
            campaign [label="Campaign", fillcolor="#CFD8DC"]
            tag [label="Tag", fillcolor="#CFD8DC"]
            medication [label="Medication", fillcolor="#CFD8DC"]
            turnfeegroup [label="TurnFeeGroup", fillcolor="#CFD8DC"]
        }
        specialty -> study [style=invis]
        province -> locality
    }

    // === FORCE COLUMN ALIGNMENT WITH INVISIBLE EDGES ===
    // Column 1: Pets -> Cart
    petowner -> cart [style=invis, weight=10]
    // Column 2: Vets -> Requests
    veterinarian -> servicerequest [style=invis, weight=10]
    // Column 3: Services -> Visits
    service -> vetvisit [style=invis, weight=10]

    // Force Reference Data to bottom
    cart -> specialty [style=invis, weight=10]
    servicerequest -> campaign [style=invis, weight=10]
    vetvisit -> turnfeegroup [style=invis, weight=10]

    // === INTERNAL CLUSTER EDGES ===
    petowner -> pet [label="1:N"]
    pet -> petvaccine [label="1:N"]
    pet -> petstudy [label="1:N"]

    veterinarian -> availability
    veterinarian -> unavailability
    veterinarian -> vet_specialty
    veterinarian -> vet_neighborhood

    grupo -> category [label="1:N"]
    category -> service [label="1:N"]
    service -> prices [label="1:N"]
    service -> discounts [label="1:N"]

    cart -> cartitem [label="1:N"]
    cart -> cartresumeitem
    cart -> cartpetreason

    servicerequest -> statehistory [label="1:N"]
    servicerequest -> vetasked [label="1:N"]
    servicerequest -> payreminder
    vetasked -> vetreminder

    vetvisit -> visit_pets
    vetvisit -> vetvisitreport [label="1:N"]
    vetvisit -> vetvisitpetreason
    vetvisitreport -> vetvisitfollowup
    vetvisit -> receipt [style=dashed]

    // === CROSS-CLUSTER RELATIONSHIPS ===
    auth_user -> petowner [label="1:1 opt", style=dashed]
    auth_user -> veterinarian [label="1:1"]

    petowner -> cart [label="1:N"]
    petowner -> servicerequest [label="1:N"]
    servicerequest -> cart [label="1:1", constraint=false]
    vetasked -> veterinarian [constraint=false]
    vetvisit -> servicerequest [style=dashed, constraint=false]

    // Reference links
    petvaccine -> vaccine [constraint=false]
    petstudy -> study [constraint=false]
    vet_specialty -> specialty [constraint=false]
    vet_neighborhood -> neighborhood [constraint=false]
    cartitem -> service [constraint=false]
}
