import Polling from "../../../utils/polling";

let busy = false;
let fleetCANFilters = [
  {
    can_id: "123-456",
    interval: 789
  },
  {
    can_id: "1",
    interval: 1000
  },
  {
    can_id: "1000",
    interval: 1
  }
]
let fleet = {
  name: "US-WEST",
  log_level: "info",
  canbus: { enabled: true, data_logger_enabled: true, max_mem_buffer_size: 1, max_disk_buffer_size: 2, filters: fleetCANFilters },
  idps_enabled: true,
  vehicles: ["USWESTVIN12345678", "USWESTVIN12345679", "USWESTVIN12345670"],
  vehicles_count: 3,
}
let fleets = [
  {
    name: "US-WEST",
    log_level: "info",
    canbus: { enabled: true, data_logger_enabled: true, max_mem_buffer_size: 1, max_disk_buffer_size: 2, filters: fleetCANFilters },
    idps_enabled: true,
    vehicles: ["USWESTVIN12345678", "USWESTVIN12345679", "USWESTVIN12345670"],
    vehicles_count: 3,
  },
  {
    name: "US-CENTRAL",
    log_level: "warning",
    canbus: { enabled: false, data_logger_enabled: false, max_mem_buffer_size: 0, max_disk_buffer_size: 0 },
    idps_enabled: true,
    vehicles: ["USCENTVIN12345678", "USCENTVIN12345679", "USCENTVIN12345670"],
    vehicles_count: 3,
  },
  {
    name: "US-EAST",
    log_level: "error",
    canbus: { enabled: true },
    idps_enabled: true,
    vehicles: ["USEASTVIN12345678", "USEASTVIN12345679", "USEASTVIN12345670"],
    vehicles_count: 3,
  },
];
let totalFleets = 3;
let fleetVehicles = ["USWESTVIN12345678", "USWESTVIN12345679", "USWESTVIN12345670"];
let totalFleetVehicles = 3;
let totalFleetCANFilters = 3;

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

export const useFleetContext = () => ({
  busy,

  fleet,
  fleets,
  totalFleets,
  addFleet: jest.fn(),
  getFleet: jest.fn(),
  getFleets: jest.fn(),
  updateFleet: jest.fn(),
  deleteFleet: jest.fn(),

  fleetVehicles,
  totalFleetVehicles,
  watchFleetVehicles: new Polling(jest.fn(), 0),
  getFleetVehicles: jest.fn().mockImplementation((name, search, _token) => {
    const result = [
      {
        vin: "USWESTVIN12345678",
        connected: false,
        connectedHMI: false,
        trex_version: "",
      },
      {
        vin: "USWESTVIN12345679",
        connected: true,
        connectedHMI: true,
        trex_version: "",
      },
      {
        vin: "USWESTVIN12345670",
        connected: false,
        connectedHMI: false,
        trex_version: "",
      },
    ];
    return Promise.resolve(result);
  }),
  addFleetVehicles: jest.fn(),
  deleteFleetVehicles: jest.fn(),

  fleetCANFilters,
  totalFleetCANFilters,
  getFleetCANFilters: jest.fn(),
  addFleetCANFilter: jest.fn(),
  updateFleetCANFilter: jest.fn(),
  deleteFleetCANFilter: jest.fn(),
});
