CREATE TABLE TELEGRAM_BOT (
    ID               NUMBER        NOT NULL,
    TOKEN            VARCHAR2(100) NOT NULL,
    BOT_ID           VARCHAR2(100) NOT NULL,
    NAME             VARCHAR2(500) NOT NULL,
    USERNAME         VARCHAR2(100) NOT NULL,
    DESCRIPTION      VARCHAR2(4000), 
    IDATIVO          VARCHAR2(1)   DEFAULT 'S' NOT NULL,
    NRORG            NUMBER 	   DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    DTINCLUSAO       DATE          DEFAULT SYSDATE,
    DTULTATU         DATE          DEFAULT SYSDATE,
    NRORGINCLUSAO    NUMBER        DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')	NULL,
    CDOPERINCLUSAO   VARCHAR2(12)  DEFAULT '1' NULL,
    NRORGULTATU      NUMBER        DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')	NULL,
    CDOPERULTATU     VARCHAR2(12)  DEFAULT '1',
		CONSTRAINT PK_TELEGRAM_BOT          PRIMARY KEY(ID),
		CONSTRAINT CKC_IDATIVO_TELEGRAM_BOT CHECK (IDATIVO IN ('S','N'))
)
/

CREATE TABLE TELEGRAM_GROUP (
    ID               NUMBER        NOT NULL,
    GROUP_ID         VARCHAR2(100) NOT NULL,
    TITLE            VARCHAR2(500) NOT NULL,
    DESCRIPTION      VARCHAR2(4000),
    IDATIVO          VARCHAR2(1)   DEFAULT 'S' NOT NULL,
    NRORG            NUMBER 	   DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    DTINCLUSAO       DATE          DEFAULT SYSDATE,
    DTULTATU         DATE          DEFAULT SYSDATE,
    NRORGINCLUSAO    NUMBER        DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')	NULL,
    CDOPERINCLUSAO   VARCHAR2(12)  DEFAULT '1' NULL,
    NRORGULTATU      NUMBER        DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')	NULL,
    CDOPERULTATU     VARCHAR2(12)  DEFAULT '1',
		CONSTRAINT PK_TELEGRAM_GROUP          PRIMARY KEY(ID),
		CONSTRAINT CKC_IDATIVO_TELEGRAM_GROUP CHECK (IDATIVO IN ('S','N'))
)
/

CREATE TABLE TELEGRAM_BOT_GROUP (
    ID                NUMBER NOT NULL,
    TELEGRAM_BOT_ID   NUMBER NOT NULL,
    TELEGRAM_GROUP_ID NUMBER NOT NULL,
    IDATIVO          VARCHAR2(1)   DEFAULT 'S' NOT NULL,
    NRORG            NUMBER 	   DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    DTINCLUSAO       DATE          DEFAULT SYSDATE,
    DTULTATU         DATE          DEFAULT SYSDATE,
    NRORGINCLUSAO    NUMBER        DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')	NULL,
    CDOPERINCLUSAO   VARCHAR2(12)  DEFAULT '1' NULL,
    NRORGULTATU      NUMBER        DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')	NULL,
    CDOPERULTATU     VARCHAR2(12)  DEFAULT '1',
		CONSTRAINT PK_TELEGRAM_BOT_GROUP          PRIMARY KEY(ID),
		CONSTRAINT FK_TELE_BOT_GROUP_ID          FOREIGN KEY (TELEGRAM_BOT_ID) REFERENCES TELEGRAM_BOT (ID),
		CONSTRAINT FK_TELE_BOT_GROUP_GROUP        FOREIGN KEY (TELEGRAM_GROUP_ID) REFERENCES TELEGRAM_GROUP (ID),
		CONSTRAINT CKC_IDATIVO_TELEG_BOT_GROUP CHECK (IDATIVO IN ('S','N'))
)
/

CREATE INDEX TELE_BOT_GROUP_ID_FK ON TELEGRAM_BOT_GROUP (TELEGRAM_BOT_ID)
/

CREATE INDEX TELE_BOT_GROUP_FK ON TELEGRAM_BOT_GROUP (TELEGRAM_GROUP_ID)
/