CREATE TABLE TBEMAIL_TEMPLATE (
    ID INTEGER NOT NULL,
    DESCRICAO VARCHAR(200),
    ASSUNTO VARCHAR(100),
    TIPO INTEGER,
    TEMPLATE BLOB SUB_TYPE 1 SEGMENT SIZE 80,
    SITUACAO_PEDIDO INTEGER,
	DADOS_ENDERECO VARCHAR(500),
	EMAIL_FINANCEIRO VARCHAR(50),
	CELULAR_EMPRESA VARCHAR(50),
	EMAIL_COMERCIAL VARCHAR(50),
	TELEFONE_EMPRESA VARCHAR(50),
	FALE_CONOSCO VARCHAR(100),
    DATAHORA TIMESTAMP,
	STATUS INTEGER DEFAULT 1 NOT NULL);

ALTER TABLE TBEMAIL_TEMPLATE
ADD CONSTRAINT PK_TBEMAIL_TEMPLATE
PRIMARY KEY (ID);

COMMENT ON COLUMN TBEMAIL_TEMPLATE.TIPO IS
'TIPO DO TEMPLATE:
1 - PEDIDOS;
2 - COBRANCA BOLETOS;';

COMMENT ON COLUMN TBEMAIL_TEMPLATE.SITUACAO_PEDIDO IS
'SITUACAO PARA TIPOS DE PEDIDOS:
1 - PEDIDO CONFIRMADO;
2 - PEDIDO NAO CONFIRMADO;';

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

CREATE SEQUENCE GTBEMAIL_TEMPLATE;

SET TERM ^ ;

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

SET TERM ; ^


CREATE INDEX ITBEMAIL_TEMPLATE_01
ON TBEMAIL_TEMPLATE (TIPO);

CREATE INDEX ITBEMAIL_TEMPLATE_02
ON TBEMAIL_TEMPLATE (STATUS);

