CREATE TABLE TBPSP_CONFIG (
    ID INTEGER NOT NULL,
    PSP_ID INTEGER DEFAULT 0 NOT NULL,
    CHAVE_PIX VARCHAR(200),
    CLIENT_ID VARCHAR(500),
    CLIENT_SECRET VARCHAR(500),
    DEVELOPER_APP_KEY VARCHAR(200),
    CERTIFICADO_FILE_PFX BLOB SUB_TYPE 0 SEGMENT SIZE 80,
    CERTIFICADO_FILE_CRT BLOB SUB_TYPE 1 SEGMENT SIZE 80,
    CERTIFICADO_FILE_KEY_CRT BLOB SUB_TYPE 1 SEGMENT SIZE 80,
    CERTIFICADO_NOME VARCHAR(200),
    CERTIFICADO_SENHA VARCHAR(50),
    CERTIFICADO_VALIDADE DATE,
    AMBIENTE INTEGER DEFAULT 1 NOT NULL,
    STATUS INTEGER DEFAULT 1 NOT NULL,
    TIPO INTEGER DEFAULT 1 NOT NULL,
    DATAHORA TIMESTAMP DEFAULT LOCALTIMESTAMP NOT NULL);

ALTER TABLE TBPSP_CONFIG
ADD CONSTRAINT PK_TBPSP_CONFIG
PRIMARY KEY (ID);

COMMENT ON COLUMN TBPSP_CONFIG.DEVELOPER_APP_KEY IS
'CAMPO UTILIZADO PARA REQUISICOES DO BANCO DO BRASIL';

COMMENT ON COLUMN TBPSP_CONFIG.AMBIENTE IS
'TIPO DE AMBIENTE PARA PSP:
1 - SANDBOX(TESTES);
2 - PRODUCAO;';

COMMENT ON COLUMN TBPSP_CONFIG.STATUS IS
'STATUS DO REGISTRO
0 - INATIVO;
1 - ATIVO;';

COMMENT ON COLUMN TBPSP_CONFIG.TIPO IS
'TIPO DE CONFIGURACAO PARA PSP:
1 - PIX;
2 - BOLETO;';

CREATE SEQUENCE GTBPSP_CONFIG;

SET TERM ^ ;

create trigger ttbpsp_config_b01i for tbpsp_config
active before insert position 0
as
begin
  if (new.id is null) then
    new.id = gen_id(gtbpsp_config,1);
end
^

SET TERM ; ^


CREATE INDEX ITBPSP_CONFIG_01
ON TBPSP_CONFIG (PSP_ID);

CREATE INDEX ITBPSP_CONFIG_02
ON TBPSP_CONFIG (CHAVE_PIX);

CREATE INDEX ITBPSP_CONFIG_03
ON TBPSP_CONFIG (AMBIENTE);

CREATE INDEX ITBPSP_CONFIG_04
ON TBPSP_CONFIG (STATUS);

CREATE INDEX ITBPSP_CONFIG_05
ON TBPSP_CONFIG (TIPO);

