package org.oasis.datacore.sample.citizenkin;

import org.oasis.datacore.core.meta.model.*;
import org.oasis.datacore.sample.DatacoreSampleBase;
import org.springframework.stereotype.Component;

/**
 * Electoral roll registration request. To be valid, the resource MUST include CKEnvelope mixin.
 *
 * NOTE: this models the specifically French procedure. This has very
 * little applicability to other countries; therefore for clarity the
 * field names are in the original French.
 *
 * User: schambon
 * Date: 12/24/13
 */
@Component
public class CitizenKinElectionModelInitializer extends DatacoreSampleBase {


    public static final String CITIZENKIN_ENVELOPE_MIXIN = "citizenkin.envelope";
    public static final String CITIZENKIN_PROCEDURE_ELECTORAL_ROLL_REGISTRATION = "citizenkin.procedure.electoral_roll_registration";

    public static final String STRING_TYPE = DCFieldTypeEnum.STRING.getType();
    public static final String DATE_TYPE = DCFieldTypeEnum.DATE.getType();

    @Override
    public void init() {

        DCMixin envelope = new DCMixin(CITIZENKIN_ENVELOPE_MIXIN);
        envelope.addField(new DCField("definition_uuid", STRING_TYPE, true, 10));
        envelope.addField(new DCField("definition_name", STRING_TYPE, true, 10));
        envelope.addField(new DCField("initiator", STRING_TYPE, true, 10));
        envelope.addField(new DCField("recipient", STRING_TYPE, false, 10));
        envelope.addField(new DCField("state", STRING_TYPE, true, 10));
        envelope.addField(new DCField("start_date", DATE_TYPE, true, 0));
        envelope.addField(new DCField("modify_date", DATE_TYPE, false, 0));
        envelope.addField(new DCField("administration_id", STRING_TYPE, true, 10));

        modelAdminService.addMixin(envelope);


        DCModel model = new DCModel(CITIZENKIN_PROCEDURE_ELECTORAL_ROLL_REGISTRATION);
        model.addField(new DCField("nom_de_famille", STRING_TYPE, true, 0));
        model.addField(new DCField("nom_d_usage", STRING_TYPE, false, 0));
        model.addField(new DCField("prenom", STRING_TYPE, true, 0));
        model.addField(new DCField("sexe", STRING_TYPE, true, 0));
        model.addField(new DCField("date_de_naissance", DATE_TYPE, true, 0));
        model.addField(new DCField("commune_de_naissance", STRING_TYPE, true, 0));
        model.addField(new DCField("code_departement_de_naissance", STRING_TYPE, false, 0));
        model.addField(new DCField("libelle_territoire_de_naissance_outremer", STRING_TYPE, false, 0));
        model.addField(new DCField("pays_de_naissance", STRING_TYPE, true, 0));

        /* One of:
        "premiere_demande"
        "demenagement_meme_commune"
        "changement_commune"
         */
        model.addField(new DCField("type_de_demande", STRING_TYPE, true, 0));

        model.addField(new DCField("commune_origine", STRING_TYPE, false, 0));
        model.addField(new DCField("code_departement_origine", STRING_TYPE, false, 0));
        model.addField(new DCField("libelle_territoire_outremer_origine", STRING_TYPE, false, 0));

        model.addField(new DCField("ambassade_poste_consulaire_origine", STRING_TYPE, false, 0));
        model.addField(new DCField("pays_origine", STRING_TYPE, false, 0));

        model.addField(new DCField("adresse1", STRING_TYPE, true, 0));
        model.addField(new DCField("adresse2", STRING_TYPE, false, 0));
        model.addField(new DCField("code_postal", STRING_TYPE, true, 0));
        model.addField(new DCField("commune", STRING_TYPE, true, 0));
        model.addField(new DCField("telephone", STRING_TYPE, false, 0));
        model.addField(new DCField("courriel", STRING_TYPE, false, 0));

        /*
         * in January 2014: points to a CK-local URL
         * Later: points to a Digital Safe resource (somehow)
         */
        model.addField(new DCField("justificatif_identite", STRING_TYPE, true, 0));
        model.addField(new DCListField("justificatifs_domicile", new DCField("justificatif_domicile", STRING_TYPE, true, 0)));


        model.addMixin(modelAdminService.getMixin(CITIZENKIN_ENVELOPE_MIXIN));

        modelAdminService.addModel(model);
    }
}

@@ -646,32 +646,42 @@
  CITIZENKIN_
+PROCEDURE_
 ENVELOPE
 _MIXIN = %22ci
@@ -668,22 +668,16 @@
 ENVELOPE
-_MIXIN
  = %22citi
@@ -683,16 +683,26 @@
 izenkin.
+procedure.
 envelope
@@ -993,16 +993,92 @@
 Type();%0A
+    public static final String LONG_TYPE = DCFieldTypeEnum.LONG.getType();%0A%0A
 %0A    @Ov
@@ -1121,20 +1121,20 @@
      DCM
-ixin
+odel
  envelop
@@ -1144,20 +1144,20 @@
  new DCM
-ixin
+odel
 (CITIZEN
@@ -1164,104 +1164,26 @@
 KIN_
-ENVELOPE_MIXIN);%0A        envelope.addField(new DCField(%22definition_uuid%22, STRING_TYPE, true, 10)
+PROCEDURE_ENVELOPE
 );%0A 
@@ -1327,32 +1327,33 @@
 G_TYPE, true, 10
+0
 ));%0A        enve
@@ -1697,16 +1697,90 @@
 ion_id%22,
+ LONG_TYPE, true, 100));%0A        envelope.addField(new DCField(%22comments%22,
  STRING_
@@ -1781,31 +1781,31 @@
 TRING_TYPE, 
-tru
+fals
 e, 
-1
 0));%0A%0A      
@@ -1828,20 +1828,20 @@
 ice.addM
-ixin
+odel
 (envelop
@@ -1933,16 +1933,116 @@
 ATION);%0A
+%0A        model.addField(new DCResourceField(%22envelope%22, CITIZENKIN_PROCEDURE_ENVELOPE, true, 10));%0A%0A
         
@@ -4192,88 +4192,8 @@
 ;%0A%0A%0A
-        model.addMixin(modelAdminService.getMixin(CITIZENKIN_ENVELOPE_MIXIN));%0A%0A
     

Remove definition uuid on ck envelope