-- UDP integrations: each row is one inbound or outbound UDP socket the
-- user wants HamLog to maintain. Direction is split so a single record
-- can describe either side without nullable destination_ip oddities.
--
-- service_type drives the parser/emitter chosen at runtime:
--   inbound:
--     'wsjt'        - WSJT-X / JTDX / MSHV binary protocol (status + logged QSO)
--     'adif'        - text ADIF payload (JTAlert, GridTracker)
--     'n1mm'        - N1MM Logger+ XML (contests)
--     'remote_call' - plain text callsign, fills the entry field
--   outbound:
--     'db_updated'  - emits the just-logged QSO as ADIF
--
-- Multicast is the only way to share a port with another listener; when
-- the flag is set the manager joins the group instead of binding the
-- unicast socket.

CREATE TABLE integrations_udp (
    id              INTEGER PRIMARY KEY AUTOINCREMENT,
    direction       TEXT NOT NULL CHECK(direction IN ('inbound','outbound')),
    name            TEXT NOT NULL,
    port            INTEGER NOT NULL,
    service_type    TEXT NOT NULL,
    multicast       INTEGER NOT NULL DEFAULT 0,
    multicast_group TEXT NOT NULL DEFAULT '',
    destination_ip  TEXT NOT NULL DEFAULT '',
    enabled         INTEGER NOT NULL DEFAULT 1,
    sort_order      INTEGER NOT NULL DEFAULT 0,
    created_at      TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')),
    updated_at      TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
);

CREATE INDEX idx_integrations_udp_dir ON integrations_udp(direction, enabled, sort_order);
