-- ===============================================================================================================
-- Status Funcionário
-- ===============================================================================================================
CREATE TABLE IF NOT EXISTS public.funcionario_status (
    id BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
    descricao VARCHAR(255) NOT NULL UNIQUE
);

INSERT INTO public.funcionario_status (id, descricao) VALUES
(1, 'Ativo'),
(3, 'Inativo');

SELECT setval(pg_get_serial_sequence('public.funcionario_status','id'), (SELECT MAX(id) FROM public.funcionario_status));

-- ===============================================================================================================
-- Funcionário
-- ===============================================================================================================
CREATE TABLE IF NOT EXISTS public.funcionario (
    id BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
    uuid UUID NOT NULL UNIQUE,
    status_id BIGINT NOT NULL REFERENCES public.funcionario_status(id) ON UPDATE CASCADE ON DELETE RESTRICT,
    empresa_id BIGINT NOT NULL REFERENCES public.empresa(id) ON UPDATE CASCADE ON DELETE RESTRICT,
    nome VARCHAR(255) NOT NULL,
    have_nome_social SMALLINT NOT NULL DEFAULT 0,
    nome_social VARCHAR(255) DEFAULT NULL,
    documentCpf VARCHAR(11) NOT NULL,
    documentPis VARCHAR(11) DEFAULT NULL,
    data_nascimento DATE NOT NULL,
    tipo_filiacao_1 VARCHAR(255) DEFAULT NULL,
    filiacao_1 VARCHAR(255) DEFAULT NULL,
    tipo_filiacao_2 VARCHAR(255) DEFAULT NULL,
    filiacao_2 VARCHAR(255) DEFAULT NULL,
);