/**
 * Created by udit on 20/06/16.
 */

Meteor.methods(
  {
    addClient(
      firstName,
      middleName,
      lastName,
      suffix,
      photo,
      ssn,
      dob,
      race,
      ethnicity,
      gender,
      veteranStatus,
      disablingConditions,
      signature
    ) {
      const client = clients.insert(
        {
          firstName,
          middleName,
          lastName,
          suffix,
          photo,
          ssn,
          dob,
          race,
          ethnicity,
          gender,
          veteranStatus,
          disablingConditions,
          signature,
        }
      );
      return client;
    },
    updateClient(
      clientID,
      firstName,
      middleName,
      lastName,
      suffix,
      photo,
      ssn,
      dob,
      race,
      ethnicity,
      gender,
      veteranStatus,
      disablingConditions
    ) {
      clients.update(
        clientID, {
          $set: {
            firstName,
            middleName,
            lastName,
            suffix,
            photo,
            ssn,
            dob,
            race,
            ethnicity,
            gender,
            veteranStatus,
            disablingConditions,
          },
        }
      );
    },
    removeClient(clientID) {
      clients.remove({ _id: clientID });
    },
    addClientToHMIS(clientID) {
      const client = clients.findOne({ _id: clientID });

      const personalId = HMISAPI.createClient(client);

      let flag = false;

      if (personalId) {
        clients.remove({ _id: client._id });
        const clientBasePath = HomeConfig.hmisAPIEndpoints.clientBaseUrl.replace(
          HomeConfig.hmisAPIEndpoints.apiBaseUrl,
          ''
        );
        const schemaVersion = HomeConfig.hmisAPIEndpoints.v2015;
        const clientsPath = HomeConfig.hmisAPIEndpoints.clients;
        const url = `${clientBasePath}${schemaVersion}${clientsPath}/${personalId}`;
        flag = {
          _id: personalId,
          link: url,
        };

        responses.update({ clientID },
          { $set: { clientID: flag._id, clientSchema: schemaVersion, isHMISClient: true } },
          { multi: true }
        );
      }

      return flag;
    },

    updateClientMatchStatus(clientId, statusCode, comments, recipients) {
      return HMISAPI.updateClientMatchStatus(clientId, statusCode, comments, recipients);
    },

  }
);

@@ -2090,29 +2090,23 @@
 Schema: 
-schemaVersion
+'v2015'
 , isHMIS

update clientID on responses after uploading client