--
-- START / Maquette contentieux v0.1
--

-- om_profil
INSERT INTO om_profil (om_profil, libelle, hierarchie, om_validite_debut, om_validite_fin) VALUES
(nextval('om_profil_seq'), 'CONTENTIEUX',   0,  NULL,   NULL);


-- om_droit
INSERT INTO om_droit (om_droit, libelle, om_profil) VALUES
-- visudadi
(nextval('om_droit_seq'),   'menu_autorisation',    (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'dossier_autorisation_tab', (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'dossier_autorisation_consulter',   (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'dossier_instruction_tab',  (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'dossier_instruction_consulter',    (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'instruction_tab',  (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'instruction_consulter',    (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'consultation_tab', (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'consultation_consulter',   (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'lot_tab',  (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'lot_consulter',    (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'blocnote_tab', (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'blocnote_consulter',   (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'dossier_commission_consulter', (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'dossier_commission_tab',   (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'dossier_message_tab',  (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'dossier_message_consulter',    (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'menu_instruction', (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'dossier_instruction_display_da_di_tab',    (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'dossier_instruction_localiser-sig-externe',    (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'donnees_techniques_consulter', (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'consultation_om_fichier_consultation_telecharger', (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'consultation_fichier_telecharger', (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'instruction_om_fichier_instruction_telecharger',   (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'dossier_instruction_rapport_instruction_rediger',  (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'rapport_instruction_consulter',    (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'dossier_instruction_donnees_techniques_consulter', (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),  'document_numerise_tab',    (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),  'document_numerise_uid_telecharger',    (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),  'dossier_autorisation_document_numerise',   (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),  'dossier_document_numerise',    (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),  'dossier_autorisation_display_da_di_tab',   (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
-- contentieux
(nextval('om_droit_seq'),  'menu_contentieux',   (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),  'menu_contentieux_dashboard',   (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),  'dossier_contentieux_mes_infractions',   (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),  'dossier_contentieux_toutes_infractions',   (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),  'dossier_contentieux_mes_recours',   (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),  'dossier_contentieux_tous_recours',   (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
-- suivi contentieux
(nextval('om_droit_seq'),  'menu_suivi',   (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),  'suivi_mise_a_jour_des_dates',   (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),  'suivi_envoi_lettre_rar',   (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),  'instruction_suivi_mise_a_jour_des_dates',   (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),  'instruction_suivi_envoi_lettre_rar',   (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
-- export contentieux
(nextval('om_droit_seq'),  'menu_export',   (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),  'reqmo_pilot',   (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
-- ajout dossier contentieux
(nextval('om_droit_seq'),  'demande_nouveau_dossier_ajouter',   (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),  'petitionnaire',   (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX'))
;

-- da_type
INSERT INTO dossier_autorisation_type (dossier_autorisation_type, code, libelle, description, confidentiel, groupe) VALUES
(nextval('dossier_autorisation_type_seq'), 'RE',   'Recours',  '', 'f',    2),
(nextval('dossier_autorisation_type_seq'), 'IN',   'Infraction',   '', 'f',    2);

-- da_type_d
INSERT INTO dossier_autorisation_type_detaille (dossier_autorisation_type_detaille, code, libelle, description, dossier_autorisation_type, cerfa, cerfa_lot, duree_validite_parametrage) VALUES
(nextval('dossier_autorisation_type_detaille_seq'),    'INF',  'Infraction',   '', (SELECT dossier_autorisation_type FROM dossier_autorisation_type WHERE code = 'IN'),  4,  NULL,   0),
(nextval('dossier_autorisation_type_detaille_seq'),    'REG',  'Recours gracieux', '', (SELECT dossier_autorisation_type FROM dossier_autorisation_type WHERE code = 'RE'),  4,  NULL,   0),
(nextval('dossier_autorisation_type_detaille_seq'),    'REC',  'Recours contentieux',  '', (SELECT dossier_autorisation_type FROM dossier_autorisation_type WHERE code = 'RE'),  4,  NULL,   0);

-- di_type
INSERT INTO dossier_instruction_type (dossier_instruction_type, code, libelle, description, dossier_autorisation_type_detaille, suffixe, mouvement_sitadel) VALUES
(nextval('dossier_instruction_type_seq'),    'P',    'Initial',  '', (SELECT dossier_autorisation_type_detaille FROM dossier_autorisation_type_detaille WHERE code = 'INF'), 't',    'DEPOT'),
(nextval('dossier_instruction_type_seq'),    'P',    'Initial',  '', (SELECT dossier_autorisation_type_detaille FROM dossier_autorisation_type_detaille WHERE code = 'REG'), 't',    'DEPOT'),
(nextval('dossier_instruction_type_seq'),    'P',    'Initial',  '', (SELECT dossier_autorisation_type_detaille FROM dossier_autorisation_type_detaille WHERE code = 'REC'), 't',    'DEPOT');
INSERT INTO demande_type (demande_type, code, libelle, description, demande_nature, groupe, dossier_instruction_type, dossier_autorisation_type_detaille, contraintes, qualification, evenement, document_obligatoire) VALUES
(nextval('demande_type_seq'),    'DI',   'Dépôt initial',    '', 1,  2,  (SELECT dossier_instruction_type FROM dossier_instruction_type WHERE dossier_autorisation_type_detaille = (SELECT dossier_autorisation_type_detaille FROM dossier_autorisation_type_detaille WHERE code = 'INF')), (SELECT dossier_autorisation_type_detaille FROM dossier_autorisation_type_detaille WHERE code = 'INF'), NULL,   't',    34, ''),
(nextval('demande_type_seq'),    'DI',   'Dépôt initial',    '', 1,  2,  (SELECT dossier_instruction_type FROM dossier_instruction_type WHERE dossier_autorisation_type_detaille = (SELECT dossier_autorisation_type_detaille FROM dossier_autorisation_type_detaille WHERE code = 'REG')), (SELECT dossier_autorisation_type_detaille FROM dossier_autorisation_type_detaille WHERE code = 'REG'), NULL,   't',    34, ''),
(nextval('demande_type_seq'),    'DI',   'Dépôt initial',    '', 1,  2,  (SELECT dossier_instruction_type FROM dossier_instruction_type WHERE dossier_autorisation_type_detaille = (SELECT dossier_autorisation_type_detaille FROM dossier_autorisation_type_detaille WHERE code = 'REC')), (SELECT dossier_autorisation_type_detaille FROM dossier_autorisation_type_detaille WHERE code = 'REC'), NULL,   't',    34, '');

-- om_widget
INSERT INTO om_widget (om_widget, libelle, lien, texte, type) VALUES
(nextval('om_widget_seq'),    'Mes AITs', 'dossiers_limites', '', 'file');

-- om_dashboard
INSERT INTO om_dashboard (om_dashboard, om_profil, bloc, position, om_widget) VALUES
(nextval('om_dashboard_seq'),    (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX'), 'C3',   2,  (SELECT om_widget FROM om_widget WHERE libelle = 'Mes AITs')),
(nextval('om_dashboard_seq'),    (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX'), 'C2',   1,  5),
(nextval('om_dashboard_seq'),    (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX'), 'C3',   1,  4),
(nextval('om_dashboard_seq'),    (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX'), 'C1',   2,  9),
(nextval('om_dashboard_seq'),    (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX'), 'C1',   1,  12);

--
-- END / Maquette contentieux v0.1
--

--
-- START / Maquette contentieux v0.2
--

-- om_droit
INSERT INTO om_droit (om_droit, libelle, om_profil) VALUES
-- service consulté
(nextval('om_droit_seq'),   'menu_demande_avis',    (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'demande_avis_encours', (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'demande_avis_passee',   (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'demande_avis',  (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'demande_avis_document_numerise',  (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'consultation_retour_avis_service',  (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'consultation_modifier',  (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'document_numerise',  (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'dossier_contentieux_donnees_techniques_consulter',  (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'dossier_contentieux_mes_infractions_donnees_techniques_consulter',  (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'dossier_contentieux_toutes_infractions_donnees_techniques_consulter',  (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'dossier_contentieux_mes_recours_donnees_techniques_consulter',  (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'dossier_contentieux_tous_recours_donnees_techniques_consulter',  (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX')),
(nextval('om_droit_seq'),   'instruction',  (SELECT om_profil FROM om_profil WHERE libelle = 'CONTENTIEUX'));

-- service
INSERT INTO service (abrege, libelle, adresse, adresse2, cp, ville, email, delai, service, consultation_papier, notification_email, om_validite_debut, om_validite_fin, type_consultation, edition, om_collectivite, delai_type) VALUES
('CTX', 'Contentieux',  '', '', '', '', '', 2,  nextval('service_seq'),    'f',    'f',    NULL,   NULL,   'avec_avis_attendu',    9,  1,  'mois');

-- direction
INSERT INTO direction (direction, code, libelle, description, chef, om_validite_debut, om_validite_fin, om_collectivite) VALUES
(nextval('direction_seq'), 'CTX',  'Dir. Contentieux', '', 'Chef', NULL,   NULL,   1);

-- division
INSERT INTO division (division, code, libelle, description, chef, direction, om_validite_debut, om_validite_fin) VALUES
(nextval('division_seq'),    'A',    'Contentieux A',    '', 'chef', (SELECT direction FROM direction WHERE code = 'CTX'),  NULL,   NULL);

-- evenement
INSERT INTO evenement (evenement, libelle, action, etat, delai, accord_tacite, delai_notification, lettretype, consultation, avis_decision, restriction, type, evenement_retour_ar, evenement_suivant_tacite, evenement_retour_signature, autorite_competente, retour, non_verrouillable, phase) VALUES
(nextval('evenement_seq'),   'Réponse au recours - Rejet type',   NULL,   NULL,   0,  'Non',  0,  'arrete',   '   ',  NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   'f',    'f',    NULL),
(nextval('evenement_seq'),   'AIT - Arrêté interruptif des travaux', NULL,   NULL,   0,  'Non',  0,  'arrete',   '   ',  NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   'f',    'f',    NULL);

-- lien_dossier_instruction_type_evenement
INSERT INTO lien_dossier_instruction_type_evenement (lien_dossier_instruction_type_evenement, dossier_instruction_type, evenement) VALUES
(nextval('lien_dossier_instruction_type_evenement_seq'),  (SELECT dossier_instruction_type FROM dossier_instruction_type WHERE code = 'P' AND dossier_autorisation_type_detaille = (SELECT dossier_autorisation_type_detaille FROM dossier_autorisation_type_detaille WHERE code = 'REG')), (SELECT evenement FROM evenement WHERE libelle = 'Réponse au recours - Rejet type')),
(nextval('lien_dossier_instruction_type_evenement_seq'),  (SELECT dossier_instruction_type FROM dossier_instruction_type WHERE code = 'P' AND dossier_autorisation_type_detaille = (SELECT dossier_autorisation_type_detaille FROM dossier_autorisation_type_detaille WHERE code = 'REC')), (SELECT evenement FROM evenement WHERE libelle = 'Réponse au recours - Rejet type')),
(nextval('lien_dossier_instruction_type_evenement_seq'),  (SELECT dossier_instruction_type FROM dossier_instruction_type WHERE code = 'P' AND dossier_autorisation_type_detaille = (SELECT dossier_autorisation_type_detaille FROM dossier_autorisation_type_detaille WHERE code = 'INF')), (SELECT evenement FROM evenement WHERE libelle = 'AIT - Arrêté interruptif des travaux'));

-- transition
INSERT INTO transition (transition, etat, evenement) VALUES
(nextval('transition_seq'),   'notifier', (SELECT evenement FROM evenement WHERE libelle = 'Réponse au recours - Rejet type')),
(nextval('transition_seq'),   'notifier', (SELECT evenement FROM evenement WHERE libelle = 'AIT - Arrêté interruptif des travaux'));

-- affectation_auto
INSERT INTO affectation_automatique (affectation_automatique, arrondissement, quartier, section, instructeur, dossier_autorisation_type_detaille, om_collectivite) VALUES
-- agglo
(nextval('affectation_automatique_seq'), NULL,   NULL,   NULL,   (SELECT instructeur FROM instructeur WHERE nom = 'ctx'), (SELECT dossier_autorisation_type_detaille FROM dossier_autorisation_type_detaille WHERE code = 'INF'), 1),
(nextval('affectation_automatique_seq'),    NULL,   NULL,   NULL,   (SELECT instructeur FROM instructeur WHERE nom = 'ctx'), (SELECT dossier_autorisation_type_detaille FROM dossier_autorisation_type_detaille WHERE code = 'REC'), 1),
(nextval('affectation_automatique_seq'),    NULL,   NULL,   NULL,   (SELECT instructeur FROM instructeur WHERE nom = 'ctx'), (SELECT dossier_autorisation_type_detaille FROM dossier_autorisation_type_detaille WHERE code = 'REG'), 1),
-- Marseille
(nextval('affectation_automatique_seq'), NULL,   NULL,   NULL,   (SELECT instructeur FROM instructeur WHERE nom = 'ctx'), (SELECT dossier_autorisation_type_detaille FROM dossier_autorisation_type_detaille WHERE code = 'INF'), 2),
(nextval('affectation_automatique_seq'),    NULL,   NULL,   NULL,   (SELECT instructeur FROM instructeur WHERE nom = 'ctx'), (SELECT dossier_autorisation_type_detaille FROM dossier_autorisation_type_detaille WHERE code = 'REC'), 2),
(nextval('affectation_automatique_seq'),    NULL,   NULL,   NULL,   (SELECT instructeur FROM instructeur WHERE nom = 'ctx'), (SELECT dossier_autorisation_type_detaille FROM dossier_autorisation_type_detaille WHERE code = 'REG'), 2);

--
-- END / Maquette contentieux v0.2
--