const data = [
  {
    email: "test@supplier.com",
    address: "address",
    company: "company",
    contact: "contact",
    created: "2021-07-14T20:09:40.98187Z",
    ecus: ["ADAS"],
    program: "Ocean",
    telephone: "555-555-5555",
    updated: "2021-07-15T21:09:40.98187Z",
  },
  {
    email: "test2@supplier.com",
    address: "address",
    company: "company",
    contact: "contact",
    created: "2021-07-16T22:09:40.98187Z",
    ecus: ["ICC", "BCM"],
    program: "Pear",
    telephone: "555-555-5555",
    updated: "2021-07-17T20:09:40.98187Z",
  },
  {
    email: "test3@supplier.com",
    address: "address",
    company: "company",
    contact: "contact",
    created: "2021-07-16T22:09:40.98187Z",
    ecus: ["BCM"],
    program: "Ocean",
    telephone: "555-555-5555",
    updated: "2021-07-17T20:09:40.98187Z",
  },
];

const suppliersAPI = {
  addSupplier: async (supplier) => {
    data.push(supplier);
    return supplier;
  },
  activateSupplier: async (_email, _token) => {
    return { message: "2022-07-14T21:02:58.998182Z" };
  },
  deleteSupplier: async (email) => {
    const index = data.findIndex((element) => element.email === email);
    if (index >= 0) data.splice(index, 1);
    return email;
  },
  getSupplier: async (email) => {
    const index = data.findIndex((element) => element.email === email);
    return data[index];
  },
  getSuppliers: async () => {
    return { data };
  },
  updateSupplier: async (email, supplier) => {
    const index = data.findIndex((element) => element.email === email);
    if (index >= 0) data[index] = supplier;
    return supplier;
  },
  getManufactureCert: async () => {
    return {public_key:"-----BEGIN CERTIFICATE-----\nTEST\n-----END CERTIFICATE-----",private_key:"-----BEGIN RSA PRIVATE KEY-----\nTEST\n-----END RSA PRIVATE KEY-----","serial_number":"66:c8:45:20:bd:75:04:79:e8:5e:0e:46:5b:5c:1a:21:8b:ea:81:9f","type":"rsa"}
  },
};

export default suppliersAPI;
