CREATE TABLE PARAM_CENTR_ASSINATURA (
  ID                     NUMBER NOT NULL,
   DSTOKENCERTSIGN        VARCHAR2(100),  
	NMSENDERCERTSIGN       VARCHAR2(100),  
	DSEMAILSENDERCERTSIGN  VARCHAR2(100),  
	NRCPFSENDERCERTSIGN    VARCHAR2(11),          
	IDPADRAOASSINACERTSIGN VARCHAR2(1),    
	NRTIPODOCCERTSIGN      NUMBER,  
  NRORG             NUMBER 	      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
  IDATIVO           VARCHAR2(1)     DEFAULT 'S'					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 CK_IDATIVO_PAR_CENT_ASSINA CHECK (IDATIVO IN ('S','N')),
      CONSTRAINT PK_PARAM_CENTR_ASSINATURA PRIMARY KEY (ID)
)
/

CREATE TABLE ROTAS_CENTR_ASSINATURA (
  ID              NUMBER NOT NULL,
  DSCHAVEASSINAT  VARCHAR2(100) NOT NULL,
	DSURLBASE       VARCHAR2(1000) NOT NULL,
	DSROTAASSINAT   VARCHAR2(1000) NOT NULL,
	CLIENT_ID        VARCHAR2(100) NOT NULL,
	CLIENT_SECRET    VARCHAR2(100) NOT NULL,
  NRORG             NUMBER 	      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
  IDATIVO           VARCHAR2(1)     DEFAULT 'S'					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 CK_IDATIVO_ROTA_CENT_ASSINA CHECK (IDATIVO IN ('S','N')),
      CONSTRAINT PK_ROTAS_CENTR_ASSINATURA PRIMARY KEY (ID),
      CONSTRAINT UN_DSCHAVASS_ROTA_CENTR_ASSINA UNIQUE (DSCHAVEASSINAT)

)
/

CREATE TABLE CENTRALIZA_ASSINATURA (
  ID              NUMBER NOT NULL,
	DSCHAVEASSINAT  VARCHAR2(100) NOT NULL,
  IDDOCASSINAT    VARCHAR2(21) NOT NULL,
  NRORG             NUMBER 	      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
  IDATIVO           VARCHAR2(1)     DEFAULT 'S'					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 CK_IDATIVO_CENT_ASSINA CHECK (IDATIVO IN ('S','N')),
      CONSTRAINT PK_CENTRALIZA_ASSINATURA PRIMARY KEY (ID),
      CONSTRAINT FK_ROTAS_CENTR_ASSINATURA FOREIGN KEY (DSCHAVEASSINAT)
        REFERENCES ROTAS_CENTR_ASSINATURA (DSCHAVEASSINAT)
)
/

CREATE INDEX ROTAS_CENTR_ASSINATURA_FK ON CENTRALIZA_ASSINATURA (DSCHAVEASSINAT ASC)
/

CREATE TABLE LOG_CENTR_ASSINATURA (
  ID              NUMBER NOT NULL,
	ID_CENTR_ASSINA NUMBER NOT NULL,
  IDDOCASSINAT    VARCHAR2(21) NOT NULL,
	NRCPFSIGNATARIO VARCHAR2(11),  
  IDACEITARECUSA  CHAR(1),
  DSLOG           CLOB, 
  NRORG             NUMBER 	        DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
  IDATIVO           VARCHAR2(1)     DEFAULT 'S'					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 CK_IDATIVO_LOG_ASSINA CHECK (IDATIVO IN ('S','N')),
    CONSTRAINT CK_IDACEITARECUSA_LOG_ASSINA CHECK (IDACEITARECUSA IN ('A', 'R')),
    CONSTRAINT PK_LOG_CENTR_ASSINATURA PRIMARY KEY (ID),
    CONSTRAINT FK_LOG_CENTR_ASSINATURA FOREIGN KEY (ID_CENTR_ASSINA)
        REFERENCES CENTRALIZA_ASSINATURA (ID)
      

)
/

CREATE INDEX LOG_CENTR_ASSINATURA_FK ON LOG_CENTR_ASSINATURA (ID_CENTR_ASSINA ASC)
/