-- Insert version configuration for SRAN_BS_VIEW
INSERT INTO DB_VIEW_CONF (VIEW_NAME, ATTRIBUTE_NAME, VALUE)
VALUES ('SRAN_BS_VIEW', 'VERSION_NAME', 'Actual Network');

-- Create/Recreate the SRAN_BS_VIEW
CREATE OR REPLACE FORCE EDITIONABLE VIEW SRAN_BS_VIEW (
    OBJECT_ID,
    SRAN_BS_NAME,
    SITE_ID,
    SRAN_BS_TYPE,
    ENODEB_OBJECT_ID,
    ENODEB_NAME,
    NODEB_OBJECT_ID,
    NODEB_NAME,
    BTS_OBJECT_ID,
    BTS_NAME
) AS
WITH SELECTED_VERSION AS (
    SELECT VERSIONID AS VERSION_ID
    FROM VERSION
    WHERE NAME = (
        SELECT VALUE
        FROM DB_VIEW_CONF
        WHERE VIEW_NAME = 'SRAN_BS_VIEW'
          AND ATTRIBUTE_NAME = 'VERSION_NAME'
    )
)
SELECT
    rbs.OBJECTID AS OBJECT_ID,
    rbs.NAME AS SRAN_BS_NAME,
    site.SITEID AS SITE_ID,
    rbstype.NAME AS SRAN_BS_TYPE,
    enodeb.OBJECTID AS ENODEB_OBJECT_ID,
    enodeb.NAME AS ENODEB_NAME,
    nodeb.OBJECTID AS NODEB_OBJECT_ID,
    nodeb.NAME AS NODEB_NAME,
    bts.OBJECTID AS BTS_OBJECT_ID,
    bts.NAME AS BTS_NAME
FROM ranbsnode rbs
LEFT JOIN ranbsnodetype rbstype ON rbs.ranbstypeid = rbstype.ranbstypeid
LEFT JOIN site ON rbs.siteid = site.siteid
LEFT JOIN enodeb ON enodeb.ROLE_CONTAINER = rbs.RANBSID
LEFT JOIN nodeb ON nodeb.ROLE_CONTAINER = rbs.RANBSID
LEFT JOIN bts ON bts.ROLE_CONTAINER = rbs.RANBSID
JOIN SELECTED_VERSION v ON rbs.versionid = v.VERSION_ID;