CREATE TABLE tb_cliente (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    tipo CHAR(1) NOT NULL CHECK (tipo IN ('F', 'J')),
    inscricao VARCHAR(14) NOT NULL UNIQUE,
    insc_estadual VARCHAR(20),
    insc_municip VARCHAR(20),
    razao_social VARCHAR(80) NOT NULL,
    nome_fantasia VARCHAR(40),
    cep CHAR(8),
    uf CHAR(2),
    municipio VARCHAR(100),
    cod_mun VARCHAR(7),
    logradouro VARCHAR(80),
    numero VARCHAR(10),
    complemento VARCHAR(100),
    bairro VARCHAR(40),
    api_client_id VARCHAR(20) NOT NULL UNIQUE,
    api_secret_key_hash VARCHAR(255) NOT NULL,
    id_tb_planos UUID,
    deleted CHAR(1) NOT NULL DEFAULT '' CHECK (deleted IN ('', '*')),

    CONSTRAINT fk_planos FOREIGN KEY(id_tb_planos) REFERENCES tb_planos(id),
    CONSTRAINT fk_municipios FOREIGN KEY(cod_mun) REFERENCES tb_municipios(cod_ibge)
);