var test = test || {};

apx.test.run = async () => {
    console.log(apx.apxid.testcreatekey("philc",""))
    //alert(hit')
    //test.publish("c8d4483c-8b5d-4941-b0b1-55fc51e331a8")
    //test.getdataforjobad("c8d4483c-8b5d-4941-b0b1-55fc51e331a8")
    //console.log("test.onboardseeker('bhavesh')");
    //test.onboardseeker("bhavesh")
    //test.createjobad();
    /*const getitem = await test.getitm(
      "smatchit",
      "jobsteps",
      "bhavesh_0fd44eee-60db-4c5a-a758-42b82e9423b8_0"
    );
    console.log("getitem", getitem);
    */
    /*const res = await test.searchitem("smatchit", "jobsteps", {
      fields: "all",
      apxid: [
        "bhavesh01_eb23f2f3-881e-4014-b06b-2e78ec211baa_0",
        "bhavesh_34fa8114-70f6-4d81-ba22-adb7d795ee2b_0",
        "bhavesh_bcfff460-aa3c-4759-be5a-636e795067fc_1",
        "bhavesh_0fd44eee-60db-4c5a-a758-42b82e9423b8_0",
        "bhavesh_7cd3efdc-32ad-4c3a-9ba7-eb81440966c0_0",
      ],
    });
    console.log(res);*/
    //test.createupdatejobstep("post");
    //test.createsiret();
    //const chk = Checkjson.schema.data(apx.data.schema.seekers, getitem);
    //console.log(chk.data.itm.jobadmatchscore);
    /*if (getitem.alias) {
      const putitem = await test.putitm("smatchit", "seekers", getitem);
      console.log("putitem", putitem);
    }
     */
    /*test.seekerinfoforrecruiter([  "0fd44eee-60db-4c5a-a758-42b82e9423b8",
    "cca83adb-3c8d-46bc-9001-ae50b7eab556",
    "1737e3ce-f6ce-4d8f-8ad6-683a957996c9"],"adminbhavesh")
    */
    //console.log(await test.getitm("smatchit","seekers","newuser01"))
    //test.updatesiret();
  };


test.searchitem = async (tribe, objectname, searchbody) => {
  console.log(
    "post ",
    `/api/apxtri/odmdb/searchitms/${tribe}/${objectname} with:`,
    searchbody
  );
  const getitm = {
    method: "post",
    url: `/api/apxtri/odmdb/searchitms/${tribe}/${objectname}`,
    data: searchbody,
    headers: apx.data.headers,
  };
  const repitm = await axios(getitm);
  if (repitm.status == 200) {
    return repitm.data.data;
  } else {
    return repitm;
  }
};
test.createupdatejobstep = async (method) => {
  const jobstep = {
"jobstepid":"bhavesh_78731a7e-61a5-489c-8b3b-2cddcf13f127_0","jobadid":"78731a7e-61a5-489c-8b3b-2cddcf13f127","stepposition":0,"seeker":"bhavesh","recruiter":"adminbhavesh","interviewer":"adminbhavesh","state":"apply","jobsteptype":"firstcontact","title":"1st contact","iconurl":"https://smatchit.io/images/interview.png","meetingformat":"","selectedmeeting":"","jobsteplocation":{"type":"street","housenumber":"","street":"Avenue de Saint-Charles","name":"Avenue de Saint-Charles","label":"Avenue de Saint-Charles 66000 Perpignan","postcode":"66000","citycode":"66136","city":"Perpignan","position":{"longitude":2.850371,"latitude":42.684682},"context":"66, Pyrénées-Orientales, Occitanie"},"jobstepurl":"","seekeremail":"","seekerphone":"","duration":0,"personnalmessage":"","interviewerfeedback":"","seekerfeedback":"","recruiterfeedback":"","recruiterevaluation":"","dt_book":"","starttime_book":"","endtime_book":""} ;
  const axiosreq = {
    method: method,
    url: `/api/apxtri/odmdb/itm/smatchit/jobsteps`,
    data: jobstep,
    headers: apx.data.headers,
  };
  axios(axiosreq)
    .then((rep) => console.log(rep))
    .catch((err) => {
      console.log(err);
    });
};
test.createjobad = async () => {
  const jobad = {
    jobadid: "65c9b24c-a350-4224-87b2-4ee560ff75a6",
    state: "draft",
    siret: "93088842500012",
    category: "Restaurant",
    jobtitle: "waiterrestauration",
    jobdisplayname: "Hôte de salle",
    jobadtitle: "Hôte de salle",
    candidateexperience: "4to8",
    specificskills: {
      countcashregister: 2,
      instructemployee: 2,
      productdistribution: 2,
      deliverorder: 2,
      guideclientorder: 2,
      serveplatesspecifictechnique: 2,
      organizerestaurantserving: 2,
      controlrestaurantserving: 2,
      presentwinemenu: 2,
      adviceclient: 2,
      preparesimpledishes: 2,
      barservice: 2,
      fightfoodwaste: 2,
      energyeconomy: 2,
      organizeteam: 2,
      endofmealservice: 2,
      carving: 2,
      flambeing: 2,
      advicewinetoplates: 2,
      controlstock: 2,
      coordinateevent: 2,
      recruitemployee: 2,
      cookmeatvegetable: 2,
      preparesandwich: 2,
      prepareproduct: 2,
      preparebreads: 2,
      cooktraiteur: 2,
      preparesalad: 2,
      cookconfectionery: 2,
      planproduction: 2,
    },
    knowhows: ["teamwork", "accurate", "service", "listening", "fits"],
    dealbreaker: ["ponctualitty"],
    languageskills: { french: 2, english: 3 },
    jobtype: ["cdd", "interim"],
    fulltime: "full",
    remote: 50,
    workingdayshours: [
      { day: "Thursday", hours: [{ start: "14", end: "08" }] },
    ],
    salary: 111,
    salarydevise: "€",
    salaryunit: "perhour",
    recruiter: "adminbhavesh",
    urgenthiring: false,
    jobadmbti: "",
    jobadlocation: [
      {
        type: "housenumber",
        housenumber: "23",
        street: "Rue du Dauphin",
        name: "23 Rue du Dauphin",
        label: "23 Rue du Dauphin 14600 Honfleur",
        postcode: "14600",
        citycode: "14333",
        city: "Honfleur",
        position: { properties: { longitude: 0.231993, latitude: 49.41992 } },
        context: "14, Calvados, Normandie",
      },
    ],
    critrulesalary: "",
    jobsteps: [{ jobsteptype: "firstcontact", interviewer: "adminbhavesh" }],
    description: "chatgpt job description Update",
    idealcanditate:
      "chatgpt liste de critere du candidat ideal Update By Recruiter",
  };
  const testputitm = await test.putitm("smatchit", "jobads", jobad);
  console.log(testputitm);
};
test.getitm = async (tribe, objectname, primaryid) => {
  console.log(
    "get ",
    `/api/apxtri/odmdb/itm/${tribe}/${objectname}/${primaryid}`
  );
  const getitm = {
    method: "get",
    url: `/api/apxtri/odmdb/itm/${tribe}/${objectname}/${primaryid}`,
    data: {},
    headers: apx.data.headers,
  };
  const repitm = await axios(getitm);
  if (repitm.status == 200) {
    if (!apx.data.itm) apx.data.itm = {};
    if (!apx.data.itm[objectname]) apx.data.itm[objectname] = {};
    apx.data.itm[objectname][primaryid] = repitm.data.data;
    apx.save();
    return repitm.data.data;
  } else {
    return repitm;
  }
};

test.putitm = async (tribe, objectname, data) => {
  const additm = {
    method: "put",
    url: `/api/apxtri/odmdb/itm/${tribe}/${objectname}`,
    data: data,
    headers: apx.data.headers,
  };
  return await axios(additm);
};
test.additm = async (tribe, objectname, data) => {
  const additm = {
    method: "post",
    url: `/api/apxtri/odmdb/itm/${tribe}/${objectname}`,
    data: data,
    headers: apx.data.headers,
  };

  return await axios(additm);
};
test.getdataforjobad = async () => {
  const data = {
    jobadid: "7cd3efdc-32ad-4c3a-9ba7-eb81440966c0",
    state: "publish",
    siret: "58980530800014",
    category: "Entreposage",
    jobtitle: "waiterrestauration",
    jobadtitle: "Responsable des petits-déjeuners",
    candidateexperience: "4to12",
    specificskills: {},
    knowhows: ["teamwork", "accurate", "service", "listening", "fits"],
    languageskills: {},
    jobtype: ["cdd"],
    fulltime: "full",
    remote: 0,
    workingdayshours: [
      {
        day: "Monday",
        hours: [
          {
            start: "01",
            end: "13",
          },
        ],
      },
      {
        day: "Thursday",
        hours: [
          {
            start: "02",
            end: "03",
          },
        ],
      },
    ],
    salary: 1200,
    salarydevise: "€",
    salaryunit: "perweek",
    jobsteps: [
      {
        jobsteptype: "firstcontact",
        interviewer: "admindeep",
        email: "deep@mailsac.com",
      },
      {
        jobsteptype: "call",
        interviewer: "admindeep",
        email: "deep@mailsac.com",
      },
      {
        jobsteptype: "interview",
        interviewer: "admindeep",
        email: "deep@mailsac.com",
      },
    ],
    recruiter: "admindeep",
    urgenthiring: false,
    jobadmbti: "",
    jobadlocation: [
      {
        type: "housenumber",
        housenumber: "710",
        street: "Avenue Roger Salengro",
        name: "710 Avenue Roger Salengro",
        label: "710 Avenue Roger Salengro 92370 Chaville",
        postcode: "92370",
        citycode: "92022",
        city: "Chaville",
        position: {
          properties: {
            longitude: 2.19312,
            latitude: 48.814933,
          },
        },
        context: "92, Hauts-de-Seine, Île-de-France",
      },
    ],
    critrulesalary: "",
    dt_create: "2024-09-13T12:00:52.530Z",
    seekermatchscore: [
      {
        seeker: "bhavesh",
        score: 65,
        newmatch: true,
        aboutyoutitle: "Ideale pour son serieux",
        aboutyou:
          "Capacité d'adaptation en phase avec le contexte difficile du job",
        criteria: [
          "Plusieurs année en zone difficile",
          "sens du contact client",
          "salaire demandé faible",
        ],
        distanceseekerjob: 99,
        currentlyinprocess: false,
      },
    ],
  };

  const getdata = {
    method: "put",
    url: `/api/smatchit/jobads/getdataforjobad`,
    data: data,
    headers: apx.data.headers,
  };
  axios(getdata)
    .then((rep) => {
      alert("success, check console");
      console.log(rep);
    })
    .catch((err) => {
      alert("err, check console");
      console.log(err);
    });
};

test.getitm = async (tribe, objectname, primaryid) => {
  console.log(
    "get ",
    `/api/apxtri/odmdb/itm/${tribe}/${objectname}/${primaryid}`
  );
  const getitm = {
    method: "get",
    url: `/api/apxtri/odmdb/itm/${tribe}/${objectname}/${primaryid}`,
    data: {},
    headers: apx.data.headers,
  };
  const repitm = await axios(getitm);
  if (repitm.status == 200) {
    if (!apx.data.itm) apx.data.itm = {};
    if (!apx.data.itm[objectname]) apx.data.itm[objectname] = {};
    apx.data.itm[objectname][primaryid] = repitm.data.data;
    apx.save();
    return repitm.data.data;
  } else {
    return repitm;
  }
};
test.updatesiret = async () => {
  const data = {
    recruiterstatus: "joincompany",
    businesslocation: {
      type: "housenumber",
      housenumber: "710",
      street: "Avenue Roger Salengro",
      name: "710 Avenue Roger Salengro",
      label: "710 Avenue Roger Salengro 92370 Chaville",
      postcode: "92370",
      citycode: "92022",
      city: "Chaville",
      position: {
        properties: {
          longitude: 2.19312,
          latitude: 48.814933,
        },
      },
      context: "92, Hauts-de-Seine, Île-de-France",
    },
    businessname: "D E E P",
    tradename: "DEEP D E E P",
    code_naf: "",
    category: "Entreposage",
    tranche_effectif: "",
    website: "https://www.deep.com/",
    socialnetworks: [],
    backgroundimage: "/objectimg/sirets/img/58980530800014_backgroundimage.png",
    companylogo: "/objectimg/sirets/img/58980530800014_companylogo.png",
    siret: "58980530800014",
    dt_create: "2024-09-13T11:59:55.733Z",
    subscription: [],
    maxactivejobad: 100,
    activejobad: 1,
    recruiters: ["admindeep", "tst"],
    adminrecruiters: ["admindeep"],
  };
  const upsiret = {
    method: "put",
    url: `/api/apxtri/odmdb/itm/smatchit/sirets`,
    data: data,
    headers: apx.data.headers,
  };
  axios(upsiret)
    .then((rep) => {
      alert("success, check console");
      console.log(rep);
    })
    .catch((err) => {
      alert("err, check console");
      console.log(err);
    });
};

test.createsiret=async ()=>{
const siretadd=
{"recruiterstatus":"addcompany","siret":"82269449300013","businessname":"HCHIKAT ROAYA","code_naf":"","tradename":"HCHIKAT ROAYA","category":"Service locatif","billinglocation":{"type":"housenumber","housenumber":"7","street":"Rue Konrad Adenauer","name":"7 Rue Konrad Adenauer","label":"7 Rue Konrad Adenauer 77600 Bussy-Saint-Georges","postcode":"77600","citycode":"77058","city":"Bussy-Saint-Georges","position":{"longitude":2.709801,"latitude":48.838155},"context":"77, Seine-et-Marne, Île-de-France"},"businesslocation":{"type":"housenumber","housenumber":"7","street":"Rue Konrad Adenauer","name":"7 Rue Konrad Adenauer","label":"7 Rue Konrad Adenauer 77600 Bussy-Saint-Georges","postcode":"77600","citycode":"77058","city":"Bussy-Saint-Georges","position":{"longitude":2.709801,"latitude":48.838155},"context":"77, Seine-et-Marne, Île-de-France"},"legalAddress":"7 Rue Konrad Adenauer 77600 Bussy-Saint-Georges, 77058","businessAddress":"7 Rue Konrad Adenauer 77600 Bussy-Saint-Georges, 77058","website":"https://www.royal.com","socialnetworks":[],"imgbase64_backgroundimage":"data:image/jpeg;base64,[encoded data, 14360 characters]","imgbase64_companylogo":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASUAAACsCAMAAAAKcUrhAAAAflBMVEX///8AAAAaGhojIyP8/Pzh4eFkZGTQ0NDl5eW9vb2fn5+ampouLi4EBAQxMTEzMzOrq6vx8fGSkpKIiIimpqb39/ft7e3KyspMTExpaWnX19fLy8seHh7k5OSCgoK0tLREREQTExM7Ozt5eXlcXFxycnJdXV1TU1ONjY1oaGgvqrUZAAAI+klEQVR4nO2diXqyOhBAGQER0ArI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rxAb1bk1Ze18GWvLXHZY2PYEUuERRlM9N5ZZ4fpQ30SYZdKc9oSWnVouuhZ7fcpvorN0t9SVC4a0NOy9ozJKdlpXS5odbepitDCuRNRGL7Xlbqsm7FZbZvDczKqwSKo8lbfZhUSuxr59tKYBH3gTHUhbnJL/2K/EO10s0P82vn3mH1iLT80V4yed1vhV5UsGNyVoCZsOSUCwKb22zWxNbLdo7Xv9dnBcEez3Mj/qWyrxamlmBFuiDnq4zWV6aNy0JHNXYXc/8zs85rrbsGqVstnDuy1BG83gVQ7qTJ7N0bqYWfStXLjB0raI/+FheBXoqGBfCjqfxvMeDHtX07yxh+6DVGbvsm0Xtbar5NWBm8sd/nV8+7MYAPW4eEmDv/nxLkRXv8ucIJXhLqpz3StkfaTrnCdXMs8lPlNU411e1U6serPjRluYw5zWCCykfX43RJe4IaXlejYui3hOF7/O85Hh+Sb6cU10MSvxkluLi1sAth3YXr8vLnXD3LMcs+noF+O1ubVkVz10Dx+OmfnK1Ggl2LX2FzHFqV7Rg4xgDJ7zQ/CUMZAkDWcJAljCQJQxkCQP9DwsMlJcwkCUMZAkDWcJAljCQJQxkCQO1lzBQXsJAljCQJQxkCQNZwkCWMFBLAAPlJQxkCQNZwkCWMAyxtH9X/xYLU9yS/GzOy/+XlSxu6U8iaOnmd7WqbWDVfu9hs7ptHj6CVVdsD0HK2O8v8nBPY3z86Nke9+hWVeKfRFUdU8SS71ima7Bv/swRI//JN4Zr5u/f3jSaG7O5KT6yTNOt3udxdARpxO3yN7qi6j9Yxx75N39VHqJrx/wj55v/wShBEARBEARBEARBEARBEE/4DxxqsDCPrH68AAAAAElFTkSuQmCC","locationenabled":true,"notificationenabled":true,"recruiters":["newone"],"adminrecruiters":["newone"],"owner":"newone","subscription":[],"emailbilling":"bhavesh@mailsac.com","namebilling":"newone","activejobad":0,"tranche_effectif":"","backgroundimage":"","companylogo":"","whyworkhere":"","agreetorespectnorms":false,"maxactivejobad":100};
const addsiret = {
  method: "post",
  url: `/api/apxtri/odmdb/itm/smatchit/sirets`,
  data: siretadd,
  headers: apx.data.headers,
};
axios(addsiret)
  .then((rep) => {
    alert("success, check console");
    console.log(rep);
  })
  .catch((err) => {
    alert("err, check console");
    console.log(err);
  });
};


test.seekerinfoforrecruiter = async (jobadids, aliasrecruiter) => {
  // must be connectered as aliasrecruitrer or to have adminrecruiter profil for the same siret than jobads
  await axios
    .put(
      `/api/smatchit/seekers/infoseeker/${aliasrecruiter}`,
      { jobadids: jobadids },
      { headers: apx.data.headers }
    )
    .then((rep) => {
      alert("success, check console");
      console.log(rep.data);
    })
    .catch((err) => {
      alert("err, check console");
      console.log(err);
    });
};

test.publish = async (jobadid) => {
  await axios
    .put(
      `/api/smatchit/jobads/publish/${jobadid}`,
      {},
      { headers: apx.data.headers }
    )
    .then((rep) => {
      //alert("success, check console");
      console.log(rep);
    })
    .catch((err) => {
      //alert("err, check console");
      console.log(err);
    });
};
test.onboardseeker = async (seeker) => {
  await axios
    .get(`/api/smatchit/seekers/onboarding/${seeker}`, {
      headers: apx.data.headers,
    })
    .then((rep) => {
      //alert("success, check console");
      console.log(rep);
    })
    .catch((err) => {
      //alert("err, check console");
      console.log(err);
    });
};
