import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'datamodel.dart';
import 'addevent.dart';
import 'viewevents.dart';
import 'overview.dart';
import 'configuration.dart';
import 'login.dart';

void main() {
  
  EventStoreInstance events = EventStoreInstance();
  final ConfigurationStoreInstance configuration = ConfigurationStoreInstance();

  //Reset old data
  events.reset();
  configuration.reset();

  configuration.loginInformation.mail = 'admin';  // Sandbox.sensor.de  admin account
  configuration.loginInformation.password ='adminadmin';

  // Add some dummy devices
  // TODO: load from shared preferences.
  // TODO: this shall be requested from sensor.awi.de after selecting a collection in configuration.
  configuration.devices.add(Device.fromJson({'id': 8311, 'urn':'station:neumayer_iii:awi_snow_sampler_1'}));
  configuration.devices.add(Device.fromJson({'id': 4086, 'urn':'acoustic_backscatter_sensor:test'}));
  configuration.devices.add(Device.fromJson({'id': 1393, 'urn':'vessel:polarstern:hydrosweep_ds3'}));

  // Fill the textboxes in addevent with some usefull data.
  // TODO: store this in shared preferences so that last entered data reappears when restarting the app.
  events.currentEvent.urn = 'acoustic_backscatter_sensor:test';
  events.currentEvent.id = 4086;
  events.currentEvent.description = 'blabla';
  events.currentEvent.label = 'PS129_ABC';
  events.currentEvent.type = 'Deployment';
  events.currentEvent.startDate = '2022-03-09 15:06:00.000Z';
  events.currentEvent.endDate = '2022-03-09 15:08:00.000Z';

  
  //Add some dummy events to event store. Just development purpose. TODO: Remove after development.
  events.events.add(Event.fromJson({
    'id': 8311,
    'urn': 'station:neumayer_iii:awi_snow_sampler_1',
    'label': 'SML_KO21_SC01',
    'type': 'Deployment',
    'description': 'Remi tool Tag1 1 Traverse',
    'status': 'PENDING',
    'startDate': '2022-03-08T05:29:26Z',
    'endDate': '2022-03-08T06:29:26Z'
  }));
  events.events.add(Event.fromJson({
    'id': 8311,
    'urn': 'station:neumayer_iii:awi_snow_sampler_1',
    'label': 'SML_KO21_SC01',
    'type': 'Deployment',
    'description': 'Remi tool Tag1 1 Traverse',
    'status': 'PENDING',
    'startDate': '2022-03-08T05:29:26Z',
    'endDate': '2022-03-08T06:29:26Z'
  }));
  events.events.add(Event.fromJson({
    'id': 8311,
    'urn': 'station:neumayer_iii:awi_snow_sampler_1',
    'label': 'SML_KO21_SC01',
    'type': 'Deployment',
    'description': 'Remi tool Tag1 1 Traverse',
    'status': 'PENDING',
    'startDate': '2022-03-08T05:29:26Z',
    'endDate': '2022-03-08T06:29:26Z'
  }));
  events.events.add(Event.fromJson({
    'id': 8311,
    'urn': 'station:neumayer_iii:awi_snow_sampler_1',
    'label': 'SML_KO21_SC01',
    'type': 'Deployment',
    'description': 'Remi tool Tag1 1 Traverse',
    'status': 'PENDING',
    'startDate': '2022-03-08T05:29:26Z',
    'endDate': '2022-03-08T06:29:26Z'
  }));
  
  //Add some dummy eventtypes.
  // TODO: loard from shared preferences.
  // TODO: request from https://sensor.awi.de/rest/sensors/events/getAllEventTypes in configuration widget.
  configuration.eventTypes.add(EventType.fromJson({'id': 317, 'name':'Configuration'}));
  configuration.eventTypes.add(EventType.fromJson({'id': 216, 'name':'Decommissioned'}));
  configuration.eventTypes.add(EventType.fromJson({'id': 187, 'name':'Deployment'}));
  configuration.eventTypes.add(EventType.fromJson({'id': 50, 'name':'Information'}));
  configuration.eventTypes.add(EventType.fromJson({'id': 16, 'name':'Maintenance'}));

  runApp(MaterialApp(
    title: 'Mobile Event Log',
    theme: ThemeData(
      primarySwatch: Colors.blue,
    ),
    initialRoute: '/',
    routes: {
      '/': (context) => Overview(),
      '/second': (context) => const AddEvent(),
      '/third': (context) => const ViewEvents(),
      '/forth': (context) => const Configuration(),
      '/fifth': (context) => const LoginPage(),
    },
  ));
}