CREATE TABLE IF NOT EXISTS satellite_modes (
    id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    satellite_id BIGINT NOT NULL,
    source VARCHAR(20) NOT NULL,
    type VARCHAR(20) NOT NULL,
    start_time TIMESTAMP NOT NULL,
    end_time TIMESTAMP NOT NULL,
    revolution BIGINT NOT NULL,
    lat DOUBLE PRECISION NOT NULL,
    longitude DOUBLE PRECISION NOT NULL,
    duration DOUBLE PRECISION NOT NULL,
    contour_wkt TEXT,
    roll DOUBLE PRECISION NOT NULL,
    cell_num BIGINT NOT NULL DEFAULT -1,
    CONSTRAINT chk_satellite_modes_source CHECK (source IN ('SLOTS', 'COMPLAN', 'MIXED')),
    CONSTRAINT chk_satellite_modes_type CHECK (type IN ('SURVEY'))
);

CREATE INDEX IF NOT EXISTS idx_satellite_modes_satellite_id
    ON satellite_modes(satellite_id);

CREATE INDEX IF NOT EXISTS idx_satellite_modes_start_time
    ON satellite_modes(start_time);

CREATE INDEX IF NOT EXISTS idx_satellite_modes_end_time
    ON satellite_modes(end_time);

CREATE INDEX IF NOT EXISTS idx_satellite_modes_source
    ON satellite_modes(source);

CREATE INDEX IF NOT EXISTS idx_satellite_modes_satellite_interval
    ON satellite_modes(satellite_id, start_time, end_time);
