-- Public GM profiles for catalog and club trust pages.

CREATE TABLE master_profiles (
    id            UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    player_id     UUID NOT NULL UNIQUE REFERENCES players(id) ON DELETE CASCADE,
    public_slug   VARCHAR(120),
    is_public     BOOLEAN NOT NULL DEFAULT false,
    display_name  VARCHAR(255) NOT NULL,
    bio           TEXT,
    created_at    TIMESTAMPTZ NOT NULL DEFAULT now(),
    updated_at    TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE UNIQUE INDEX ux_master_profiles_public_slug
    ON master_profiles (lower(public_slug))
    WHERE public_slug IS NOT NULL;

CREATE INDEX ix_master_profiles_public
    ON master_profiles (lower(public_slug))
    WHERE is_public = true AND public_slug IS NOT NULL;
