CREATE TABLE [OPLOSSING] (
    [OPLOSSING_ID] INT PRIMARY KEY,
    [EINDDATUM] DATE,
    [RESULTEERT_IN_NAZORG_ID] INT,
    [SOORT_ENUM_ID] INT,
    [STARTDATUM] DATE,
    [VTLB] VARCHAR(255)
);

CREATE TABLE [INFORMATIEENADVIES] (
    [INFORMATIEENADVIES_ID] INT PRIMARY KEY,
    [EINDDATUM] DATE,
    [STARTDATUM] DATE
);

CREATE TABLE [GEMEENTE] (
    [GEMEENTE_ID] INT PRIMARY KEY,
    [BEGINGELDIGHEID] DATE,
    [DATUMEINDE] DATE,
    [DATUMINGANG] DATE,
    [EINDGELDIGHEID] DATE,
    [GECONSTATEERD] BIT,
    [GEMEENTECODE] VARCHAR(255),
    [GEMEENTENAAM] VARCHAR(80),
    [GEMEENTENAAM_NEN] VARCHAR(255),
    [GEOMETRIE] GEOMETRY,
    [IDENTIFICATIE] VARCHAR(255),
    [VERSIE] INT
);

CREATE TABLE [CRISISINTERVENTIE] (
    [CRISISINTERVENTIE_ID] INT PRIMARY KEY,
    [EINDDATUM] DATE,
    [KAN_HEBBEN_SCHULDHULPTRAJECT_ID] INT,
    [STARTDATUM] DATE
);

CREATE TABLE [KP_SCHLDHLPRGNST_SCHLDHLPTRJCT] (
    [KP_SCHLDHLPRGNST_SCHLDHLPTRJCT_ID] INT PRIMARY KEY,
    [SCHULDHULPORGANISATIE_ID] INT,
    [SCHULDHULPTRAJECT_ID] INT
);

CREATE TABLE [LEEFSITUATIE] (
    [LEEFSITUATIE_ID] INT PRIMARY KEY,
    [DATUMGELDIGTOT] DATE,
    [DATUMGELDIGVANAF] DATE,
    [HEEFT_FINANCIELE_SITUATIE_CLIENT_ID] INT
);

CREATE TABLE [CLIENT] (
    [CLIENT_ID] INT PRIMARY KEY,
    [CODE] VARCHAR(80),
    [GEZAGSDRAGERGEKEND] BIT,
    [JURIDISCHESTATUS] VARCHAR(80),
    [WETTELIJKEVERTEGENWOORDIGING] VARCHAR(80)
);

CREATE TABLE [SCHULDHULPTRAJECT] (
    [SCHULDHULPTRAJECT_ID] INT PRIMARY KEY,
    [BEVAT_AANMELDING_ID] INT,
    [BEVAT_INFORMATIEENADVIES_ID] INT,
    [BEVAT_INTAKE_ID] INT,
    [BEVAT_NAZORG_ID] INT,
    [BEVAT_OPLOSSING_ID] INT,
    [BEVAT_SCHULDREGELING_ID] INT,
    [BEVAT_STABILISATIE_ID] INT,
    [EINDDATUM] DATE,
    [HEEFT_PLANVANAANPAK_ID] INT,
    [HEEFT_TRAJECT_CLIENT_ID] INT,
    [OMSCHRIJVING] NVARCHAR(MAX),
    [ONDER_VERANTWOORDELIJKHEID_VAN_GEMEENTE_ID] INT,
    [STARTDATUM] DATE,
    [TOEKENNINGSDATUM] DATE,
    [TOTAALSCHULDBEDRAGBIJAANVANGSCHULD] DECIMAL(10,2),
    [UITSTROOM_UITSTROOM_ID] INT
);

CREATE TABLE [ENUMOPLOSSINGSSOORT_ENUM] (
    [ENUMOPLOSSINGSSOORT_ENUM_ID] INT PRIMARY KEY,
    VALUE VARCHAR(255)
);

INSERT INTO [ENUMOPLOSSINGSSOORT_ENUM] ([ENUMOPLOSSINGSSOORT_ENUM_ID], VALUE) VALUES
    (1, '0_AANBOD'),
    (2, 'BETALINGSREGELING'),
    (3, 'HERFINANCIERING'),
    (4, 'SANERINGSKREDIET'),
    (5, 'SCHULDBEMIDDELING');

CREATE TABLE [SCHULDHULPORGANISATIE] (
    [SCHULDHULPORGANISATIE_ID] INT PRIMARY KEY,
    [NAAM] VARCHAR(200)
);

CREATE TABLE [ENUMUITSTROOMREDEN_ENUM] (
    [ENUMUITSTROOMREDEN_ENUM_ID] INT PRIMARY KEY,
    VALUE VARCHAR(255)
);

INSERT INTO [ENUMUITSTROOMREDEN_ENUM] ([ENUMUITSTROOMREDEN_ENUM_ID], VALUE) VALUES
    (1, 'AFGEROND'),
    (2, 'INGETROKKEN'),
    (3, 'NIETVERSCHENEN'),
    (4, 'NIET_PASSEND'),
    (5, 'OVERIG'),
    (6, 'OVERLEDEN'),
    (7, 'VERHUISD'),
    (8, 'VOLDOET_NIET'),
    (9, 'ZELF');

CREATE TABLE [VOORLOPIGEVOORZIENING_] (
    [VOORLOPIGEVOORZIENING__ID] INT PRIMARY KEY,
    [EINDDATUM] DATE,
    [HEEFT_SCHULDHULPTRAJECT_ID] INT,
    [STARTDATUM] DATE
);

CREATE TABLE [SCHULDREGELING] (
    [SCHULDREGELING_ID] INT PRIMARY KEY,
    [AFGEWEZEN] DATE,
    [DATUM] DATE,
    [DATUMVERZOEKDWANGAKKOORD] DATE,
    [DWANGAKKOORD] BIT,
    [INGETROKKEN] DATE,
    [RESULTEERT_IN_OPLOSSING_ID] INT,
    [TOEGEKEND] DATE
);

CREATE TABLE [UITSTROOM] (
    [UITSTROOM_ID] INT PRIMARY KEY,
    [DATUM] DATE,
    [DATUMBEEINDIGINGSBESCHIKKING] DATE,
    [OMSCHRIJVING] NVARCHAR(MAX),
    [REDEN_ENUM_ID] INT
);

CREATE TABLE [KP_GMNT_IS_OVRGGN_IN] (
    [KP_GMNT_IS_OVRGGN_IN_ID] INT PRIMARY KEY,
    [IS_OVERGEGAAN_IN_1_ID] INT,
    [IS_OVERGEGAAN_IN_2_ID] INT
);

CREATE TABLE [PLANVANAANPAK] (
    [PLANVANAANPAK_ID] INT PRIMARY KEY,
    [DATUMAFRONDING] DATE
);

CREATE TABLE [NAZORG] (
    [NAZORG_ID] INT PRIMARY KEY,
    [EINDDATUM] DATE,
    [STARTDATUM] DATE
);

CREATE TABLE [MORATORIUM] (
    [MORATORIUM_ID] INT PRIMARY KEY,
    [DATUMAANVRAAG] DATE,
    [DATUMGOEDKEURING] DATE,
    [EINDDATUM] DATE,
    [KAN_HEBBEN_SCHULDHULPTRAJECT_ID] INT,
    [STARTDATUM] DATE
);

CREATE TABLE [STABILISATIE] (
    [STABILISATIE_ID] INT PRIMARY KEY,
    [EINDDATUM] DATE,
    [RESULTEERT_IN_SCHULDREGELING_ID] INT,
    [STARTDATUM] DATE
);

CREATE TABLE [BEGELEIDING] (
    [BEGELEIDING_ID] INT PRIMARY KEY,
    [BEVAT_SCHULDHULPTRAJECT_ID] INT,
    [EINDDATUM] DATE,
    [RESULTEERT_IN_INTAKE_ID] INT,
    [RESULTEERT_IN_NAZORG_ID] INT,
    [RESULTEERT_IN_SCHULDREGELING_ID] INT,
    [RESULTEERT_IN_STABILISATIE_ID] INT,
    [SOORT_ENUM_ID] INT,
    [STARTDATUM] DATE
);

CREATE TABLE [AANMELDING] (
    [AANMELDING_ID] INT PRIMARY KEY,
    [CRISISINTERVENTIE] BIT,
    [EINDDATUM] DATE,
    [RESULTEERT_IN_INTAKE_ID] INT,
    [STARTDATUM] DATE
);

CREATE TABLE [INTAKE] (
    [INTAKE_ID] INT PRIMARY KEY,
    [BESCHIKKINGSDATUM] DATE,
    [BESCHIKKINGSSOORT] VARCHAR(255),
    [EINDDATUM] DATE,
    [RESULTEERT_IN_INFORMATIEENADVIES_ID] INT,
    [RESULTEERT_IN__STABILISATIE_ID] INT,
    [STARTDATUM] DATE
);

CREATE TABLE [ENUMBEGELEIDINGSSOORT_ENUM] (
    [ENUMBEGELEIDINGSSOORT_ENUM_ID] INT PRIMARY KEY,
    VALUE VARCHAR(255)
);

INSERT INTO [ENUMBEGELEIDINGSSOORT_ENUM] ([ENUMBEGELEIDINGSSOORT_ENUM_ID], VALUE) VALUES
    (1, 'BESCHERMINGSBEWIND'),
    (2, 'BUDGETBEGELEIDING'),
    (3, 'BUDGETBEHEER'),
    (4, 'BUDGETCOACHING'),
    (5, 'LANGE_TERMIJN_BEGELEIDING_DFD_');

CREATE TABLE [WSNP_TRAJECT] (
    [WSNP_TRAJECT_ID] INT PRIMARY KEY,
    [DATUMGOEDKEURING] DATE,
    [DATUMVERZOEK] DATE,
    [EINDDATUM] DATE,
    [HEEFT_LEEFSITUATIE_ID] INT,
    [STARTDATUM] DATE
);

ALTER TABLE [KP_SCHLDHLPRGNST_SCHLDHLPTRJCT] ADD CONSTRAINT FK_KP_SCHLDHLPRGNST_SCHLDHLPTRJCT_1 FOREIGN KEY ([SCHULDHULPORGANISATIE_ID]) REFERENCES [SCHULDHULPORGANISATIE] ([SCHULDHULPORGANISATIE_ID]);
-- SCHULDHULPORGANISATIE (many-to-many junction, Connector_ID: 967)

ALTER TABLE [KP_SCHLDHLPRGNST_SCHLDHLPTRJCT] ADD CONSTRAINT FK_KP_SCHLDHLPRGNST_SCHLDHLPTRJCT_2 FOREIGN KEY ([SCHULDHULPTRAJECT_ID]) REFERENCES [SCHULDHULPTRAJECT] ([SCHULDHULPTRAJECT_ID]);
-- SCHULDHULPTRAJECT (many-to-many junction, Connector_ID: 967)

ALTER TABLE [KP_GMNT_IS_OVRGGN_IN] ADD CONSTRAINT FK_KP_GMNT_IS_OVRGGN_IN_1 FOREIGN KEY ([IS_OVERGEGAAN_IN_1_ID]) REFERENCES [GEMEENTE] ([GEMEENTE_ID]);
-- GEMEENTE (many-to-many junction, Connector_ID: 2233)

ALTER TABLE [KP_GMNT_IS_OVRGGN_IN] ADD CONSTRAINT FK_KP_GMNT_IS_OVRGGN_IN_2 FOREIGN KEY ([IS_OVERGEGAAN_IN_2_ID]) REFERENCES [GEMEENTE] ([GEMEENTE_ID]);
-- GEMEENTE (many-to-many junction, Connector_ID: 2233)

ALTER TABLE [STABILISATIE] ADD CONSTRAINT FK_STABILISATIE_RESULTEERT_IN FOREIGN KEY ([RESULTEERT_IN_SCHULDREGELING_ID]) REFERENCES [SCHULDREGELING] ([SCHULDREGELING_ID]);
-- RESULTEERT_IN (1 to 0..1, Connector_ID: 959)

ALTER TABLE [SCHULDHULPTRAJECT] ADD CONSTRAINT FK_SCHULDHULPTRAJECT_BEVAT FOREIGN KEY ([BEVAT_STABILISATIE_ID]) REFERENCES [STABILISATIE] ([STABILISATIE_ID]);
-- BEVAT (1 to 0..1, Connector_ID: 960)

ALTER TABLE [SCHULDHULPTRAJECT] ADD CONSTRAINT FK_SCHULDHULPTRAJECT_UITSTROOM FOREIGN KEY ([UITSTROOM_UITSTROOM_ID]) REFERENCES [UITSTROOM] ([UITSTROOM_ID]);
-- UITSTROOM (1 to 0..1, Connector_ID: 961)

ALTER TABLE [SCHULDHULPTRAJECT] ADD CONSTRAINT FK_SCHULDHULPTRAJECT_ONDER_VERANTWOORDELIJKHEID_VAN FOREIGN KEY ([ONDER_VERANTWOORDELIJKHEID_VAN_GEMEENTE_ID]) REFERENCES [GEMEENTE] ([GEMEENTE_ID]);
-- ONDER_VERANTWOORDELIJKHEID_VAN (0..* to 1, Connector_ID: 962)

ALTER TABLE [VOORLOPIGEVOORZIENING_] ADD CONSTRAINT FK_VOORLOPIGEVOORZIENING__HEEFT FOREIGN KEY ([HEEFT_SCHULDHULPTRAJECT_ID]) REFERENCES [SCHULDHULPTRAJECT] ([SCHULDHULPTRAJECT_ID]);
-- HEEFT (1 to 0..*, Connector_ID: 963)

ALTER TABLE [SCHULDHULPTRAJECT] ADD CONSTRAINT FK_SCHULDHULPTRAJECT_BEVAT_2 FOREIGN KEY ([BEVAT_SCHULDREGELING_ID]) REFERENCES [SCHULDREGELING] ([SCHULDREGELING_ID]);
-- BEVAT (1 to 0..1, Connector_ID: 964)

ALTER TABLE [SCHULDHULPTRAJECT] ADD CONSTRAINT FK_SCHULDHULPTRAJECT_HEEFT_TRAJECT FOREIGN KEY ([HEEFT_TRAJECT_CLIENT_ID]) REFERENCES [CLIENT] ([CLIENT_ID]);
-- HEEFT_TRAJECT (0..* to 1..2, Connector_ID: 965)

ALTER TABLE [SCHULDHULPTRAJECT] ADD CONSTRAINT FK_SCHULDHULPTRAJECT_HEEFT FOREIGN KEY ([HEEFT_PLANVANAANPAK_ID]) REFERENCES [PLANVANAANPAK] ([PLANVANAANPAK_ID]);
-- HEEFT (1 to 0..1, Connector_ID: 972)

ALTER TABLE [SCHULDREGELING] ADD CONSTRAINT FK_SCHULDREGELING_RESULTEERT_IN FOREIGN KEY ([RESULTEERT_IN_OPLOSSING_ID]) REFERENCES [OPLOSSING] ([OPLOSSING_ID]);
-- RESULTEERT_IN (1 to 0..1, Connector_ID: 975)

ALTER TABLE [SCHULDHULPTRAJECT] ADD CONSTRAINT FK_SCHULDHULPTRAJECT_BEVAT_3 FOREIGN KEY ([BEVAT_OPLOSSING_ID]) REFERENCES [OPLOSSING] ([OPLOSSING_ID]);
-- BEVAT (1 to 0..1, Connector_ID: 976)

ALTER TABLE [SCHULDHULPTRAJECT] ADD CONSTRAINT FK_SCHULDHULPTRAJECT_BEVAT_4 FOREIGN KEY ([BEVAT_NAZORG_ID]) REFERENCES [NAZORG] ([NAZORG_ID]);
-- BEVAT (1 to 0..1, Connector_ID: 978)

ALTER TABLE [OPLOSSING] ADD CONSTRAINT FK_OPLOSSING_RESULTEERT_IN FOREIGN KEY ([RESULTEERT_IN_NAZORG_ID]) REFERENCES [NAZORG] ([NAZORG_ID]);
-- RESULTEERT_IN (0..1 to 0..1, Connector_ID: 979)

ALTER TABLE [MORATORIUM] ADD CONSTRAINT FK_MORATORIUM_KAN_HEBBEN FOREIGN KEY ([KAN_HEBBEN_SCHULDHULPTRAJECT_ID]) REFERENCES [SCHULDHULPTRAJECT] ([SCHULDHULPTRAJECT_ID]);
-- KAN_HEBBEN (1 to 0..*, Connector_ID: 980)

ALTER TABLE [LEEFSITUATIE] ADD CONSTRAINT FK_LEEFSITUATIE_HEEFT_FINANCIELE_SITUATIE FOREIGN KEY ([HEEFT_FINANCIELE_SITUATIE_CLIENT_ID]) REFERENCES [CLIENT] ([CLIENT_ID]);
-- HEEFT_FINANCIELE_SITUATIE (1 to 0..*, Connector_ID: 981)

ALTER TABLE [WSNP_TRAJECT] ADD CONSTRAINT FK_WSNP_TRAJECT_HEEFT FOREIGN KEY ([HEEFT_LEEFSITUATIE_ID]) REFERENCES [LEEFSITUATIE] ([LEEFSITUATIE_ID]);
-- HEEFT (0..* to 1, Connector_ID: 982)

ALTER TABLE [SCHULDHULPTRAJECT] ADD CONSTRAINT FK_SCHULDHULPTRAJECT_BEVAT_5 FOREIGN KEY ([BEVAT_INTAKE_ID]) REFERENCES [INTAKE] ([INTAKE_ID]);
-- BEVAT (1 to 0..1, Connector_ID: 986)

ALTER TABLE [INTAKE] ADD CONSTRAINT FK_INTAKE_RESULTEERT_IN_ FOREIGN KEY ([RESULTEERT_IN__STABILISATIE_ID]) REFERENCES [STABILISATIE] ([STABILISATIE_ID]);
-- RESULTEERT_IN_ (1 to 0..1, Connector_ID: 987)

ALTER TABLE [SCHULDHULPTRAJECT] ADD CONSTRAINT FK_SCHULDHULPTRAJECT_BEVAT_6 FOREIGN KEY ([BEVAT_INFORMATIEENADVIES_ID]) REFERENCES [INFORMATIEENADVIES] ([INFORMATIEENADVIES_ID]);
-- BEVAT (1 to 0..1, Connector_ID: 989)

ALTER TABLE [INTAKE] ADD CONSTRAINT FK_INTAKE_RESULTEERT_IN FOREIGN KEY ([RESULTEERT_IN_INFORMATIEENADVIES_ID]) REFERENCES [INFORMATIEENADVIES] ([INFORMATIEENADVIES_ID]);
-- RESULTEERT_IN (0..1 to 0..1, Connector_ID: 990)

ALTER TABLE [CRISISINTERVENTIE] ADD CONSTRAINT FK_CRISISINTERVENTIE_KAN_HEBBEN FOREIGN KEY ([KAN_HEBBEN_SCHULDHULPTRAJECT_ID]) REFERENCES [SCHULDHULPTRAJECT] ([SCHULDHULPTRAJECT_ID]);
-- KAN_HEBBEN (1 to 0..*, Connector_ID: 991)

ALTER TABLE [BEGELEIDING] ADD CONSTRAINT FK_BEGELEIDING_RESULTEERT_IN FOREIGN KEY ([RESULTEERT_IN_SCHULDREGELING_ID]) REFERENCES [SCHULDREGELING] ([SCHULDREGELING_ID]);
-- RESULTEERT_IN (0..1 to 0..*, Connector_ID: 994)

ALTER TABLE [BEGELEIDING] ADD CONSTRAINT FK_BEGELEIDING_RESULTEERT_IN_2 FOREIGN KEY ([RESULTEERT_IN_INTAKE_ID]) REFERENCES [INTAKE] ([INTAKE_ID]);
-- RESULTEERT_IN (0..1 to 0..*, Connector_ID: 995)

ALTER TABLE [BEGELEIDING] ADD CONSTRAINT FK_BEGELEIDING_BEVAT FOREIGN KEY ([BEVAT_SCHULDHULPTRAJECT_ID]) REFERENCES [SCHULDHULPTRAJECT] ([SCHULDHULPTRAJECT_ID]);
-- BEVAT (1 to 0..*, Connector_ID: 996)

ALTER TABLE [BEGELEIDING] ADD CONSTRAINT FK_BEGELEIDING_RESULTEERT_IN_3 FOREIGN KEY ([RESULTEERT_IN_STABILISATIE_ID]) REFERENCES [STABILISATIE] ([STABILISATIE_ID]);
-- RESULTEERT_IN (0..1 to 0..*, Connector_ID: 997)

ALTER TABLE [BEGELEIDING] ADD CONSTRAINT FK_BEGELEIDING_RESULTEERT_IN_4 FOREIGN KEY ([RESULTEERT_IN_NAZORG_ID]) REFERENCES [NAZORG] ([NAZORG_ID]);
-- RESULTEERT_IN (0..1 to 0..1, Connector_ID: 998)

ALTER TABLE [SCHULDHULPTRAJECT] ADD CONSTRAINT FK_SCHULDHULPTRAJECT_BEVAT_7 FOREIGN KEY ([BEVAT_AANMELDING_ID]) REFERENCES [AANMELDING] ([AANMELDING_ID]);
-- BEVAT (1 to 0..1, Connector_ID: 1000)

ALTER TABLE [AANMELDING] ADD CONSTRAINT FK_AANMELDING_RESULTEERT_IN FOREIGN KEY ([RESULTEERT_IN_INTAKE_ID]) REFERENCES [INTAKE] ([INTAKE_ID]);
-- RESULTEERT_IN (1 to 0..1, Connector_ID: 1001)

ALTER TABLE [BEGELEIDING] ADD CONSTRAINT FK_BEGELEIDING_SOORT_ENUM_ID FOREIGN KEY ([SOORT_ENUM_ID_ENUMBEGELEIDINGSSOORT_ENUM_ID]) REFERENCES [ENUMBEGELEIDINGSSOORT_ENUM] ([ENUMBEGELEIDINGSSOORT_ENUM_ID]);
-- SOORT_ENUM_ID (1 to 1, Connector_ID: enum_ref)

ALTER TABLE [OPLOSSING] ADD CONSTRAINT FK_OPLOSSING_SOORT_ENUM_ID FOREIGN KEY ([SOORT_ENUM_ID_ENUMOPLOSSINGSSOORT_ENUM_ID]) REFERENCES [ENUMOPLOSSINGSSOORT_ENUM] ([ENUMOPLOSSINGSSOORT_ENUM_ID]);
-- SOORT_ENUM_ID (1 to 1, Connector_ID: enum_ref)

ALTER TABLE [UITSTROOM] ADD CONSTRAINT FK_UITSTROOM_REDEN_ENUM_ID FOREIGN KEY ([REDEN_ENUM_ID_ENUMUITSTROOMREDEN_ENUM_ID]) REFERENCES [ENUMUITSTROOMREDEN_ENUM] ([ENUMUITSTROOMREDEN_ENUM_ID]);
-- REDEN_ENUM_ID (1 to 1, Connector_ID: enum_ref)

