CREATE TABLE provedor_email (
    id        bigint NOT NULL,
    descricao VARCHAR2(100) NOT NULL,
    protocolo SMALLINT DEFAULT 1 NOT NULL,
    servidor  VARCHAR2(100) NOT NULL,
    porta     SMALLINT DEFAULT 587 NOT NULL,
    usuario   VARCHAR2(100) NOT NULL,
    senha     VARCHAR2(256) NOT NULL,
    seguranca SMALLINT,
    situacao  SMALLINT DEFAULT 1 NOT NULL,
    principal SMALLINT NOT NULL,
    config    json
);

ALTER TABLE provedor_email
    ADD CHECK ( protocolo IN ( 1, 2, 3 ) );

ALTER TABLE provedor_email
    ADD CHECK ( seguranca IN ( 1, 2 ) );

ALTER TABLE provedor_email
    ADD CHECK ( situacao IN ( 0, 1 ) );

ALTER TABLE provedor_email
    ADD CHECK ( principal IN ( 0, 1 ) );

COMMENT ON COLUMN provedor_email.id IS
    'Id da configuração';

COMMENT ON COLUMN provedor_email.descricao IS
    'descrição do serviço';

COMMENT ON COLUMN provedor_email.protocolo IS
    '1-SMTP (Simple Mail Transfer Protocol)
2-POP3  ( Post Office Protocol Versão 3)
3-IMAP (Internet Message Access Protocol)';

COMMENT ON COLUMN provedor_email.seguranca IS
    '1-TLS
2-SSL
';

COMMENT ON COLUMN provedor_email.principal IS
    '0-Não
1-Sim';

COMMENT ON COLUMN provedor_email.config IS
    'Demais configurações do provedor de email ';
CREATE UNIQUE INDEX provedor_email_principal ON provedor_email 
    ( 
     tipo asc, principal asc, situacao asc WHERE situacao = 1
    ) 
;