-- +goose Up
-- Per-game friend requests sent to a disguised-robot opponent. A disguised robot is a
-- shared pool account reused across games under different per-game names, so such a
-- request must never go into `friendships` (that would befriend/await the shared robot
-- account, leak that it is a bot across the requester's other games under other names,
-- and pin the in-game "request sent" state to the shared account instead of this seat).
-- Each request is recorded here against the specific game + seat, snapshotting the name
-- the player saw, so the in-game scoreboard can re-mark that one seat as already
-- requested. The robot ignores it (it never becomes a friendship); a background reaper
-- deletes a row once its game has been finished for more than the retention window.
SET search_path = backend, pg_catalog;

CREATE TABLE robot_friend_requests (
    id           uuid        PRIMARY KEY,
    requester_id uuid        NOT NULL REFERENCES accounts (account_id) ON DELETE CASCADE,
    game_id      uuid        NOT NULL REFERENCES games (game_id) ON DELETE CASCADE,
    seat         smallint    NOT NULL,
    robot_id     uuid        NOT NULL REFERENCES accounts (account_id) ON DELETE CASCADE,
    display_name text        NOT NULL,
    created_at   timestamptz NOT NULL DEFAULT now(),
    UNIQUE (requester_id, game_id, seat)
);

CREATE INDEX robot_friend_requests_requester_idx ON robot_friend_requests (requester_id);

-- +goose Down
SET search_path = backend, pg_catalog;
DROP TABLE robot_friend_requests;
