CREATE TYPE companion_type AS ENUM ('beneficial', 'neutral', 'antagonistic');

CREATE TABLE companion_relationships (
    id              UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    species_a_id    UUID NOT NULL REFERENCES species(id) ON DELETE CASCADE,
    species_b_id    UUID NOT NULL REFERENCES species(id) ON DELETE CASCADE,
    relationship    companion_type NOT NULL,
    mechanism       TEXT,
    source_url      TEXT,
    created_at      TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    UNIQUE(species_a_id, species_b_id),
    CHECK (species_a_id < species_b_id)
);

CREATE INDEX idx_companion_a ON companion_relationships(species_a_id);
CREATE INDEX idx_companion_b ON companion_relationships(species_b_id);
