import React from "react";

const CarUpdatesContext = React.createContext();

let busy = false;
let carUpdates = [
  {
    id: 1,
    vin: "1G1FP87S3GN100062",
    updatepackage_id: 18,
    status: "downloaded",
    created: "2021-07-01T22:40:07.778509Z",
    updated: "2021-07-12T18:22:13.736755Z",
    updatemanifest: {
      id: 283,
      name: "TEST UPDATE",
      version: "1000",
      description: "UPDATE DESCRIPTION",
      ecu_list: "AGS 1.0.0,AMP 1.0.0",
      created: "2021-08-20T18:37:41.960397Z",
      updated: "2021-08-20T18:37:50.007853Z",
    },
  },
];
let totalCarUpdates = 1;
let carUpdateLog = {
  data: [
    {
      id: 90,
      status: "package_install_complete",
      error_code: 0,
      created: "2021-08-23T17:06:38.410115Z",
      updated: "2021-08-23T17:06:38.410115Z",
    },
    {
      id: 89,
      carupdate_id: 283,
      status: "package_install_start",
      error_code: 0,
      created: "2021-08-23T17:06:38.030052Z",
      updated: "2021-08-23T17:06:38.030052Z",
    },
  ],
  total: 2,
};

export const CarUpdatesProvider = ({ children }) => {
  return <div data-testid="mocked-carupdatesprovider">{children}</div>;
};

export const useCarUpdatesContext = () => ({
  busy,
  carUpdates,
  totalCarUpdates,
  deployCarUpdates: jest.fn((data) => data),
  getCarUpdates: jest.fn(() => ({
    data: carUpdates,
  })),
  getLog: jest.fn(() => carUpdateLog),
  getVINUpdates: jest.fn(() => carUpdates),
  startMonitor: jest.fn(),
  stopMonitor: jest.fn(),
});
