import 'package:flutter_test/flutter_test.dart';
import 'package:garden_planner/api/http_connection.dart';
import 'package:http/http.dart' as http;
import 'package:mockito/mockito.dart';

class MockHttpClient extends Mock implements HttpConnector {
  @override

  Future<http.Response> getBeet() async {
    final mockResponse = http.Response('['
        '{"id":11,"plant_id":2,"position":0,"beet_row":0},'
        '{"id":12,"plant_id":1,"position":1,"beet_row":0},'
        '{"id":13,"plant_id":2,"position":0,"beet_row":1},'
        '{"id":14,"plant_id":1,"position":1,"beet_row":1}]', 200);

    return mockResponse;
  }


  @override
  Future<http.Response> getAllPlants() async {
    final mockResponse = http.Response('''[
      {
        "id": 1,
        "name": "Tomate",
        "description": "",
        "water_requirement": 0.8,
        "horizontal_space": 0.6,
        "vertical_space": 0.8,
        "image_path": "lib/assets/plants/tomatoes-gc17bf34c6_640.jpg",
        "times": [
          {
            "id": 1,
            "plant_id": 1,
            "color": "4294961979",
            "description": "Aussaat",
            "from_date": "2023-04-01T00:00:00.000Z",
            "until_date": "2023-05-15T00:00:00.000Z",
            "action_needed": true
          },
          {
            "id": 2,
            "plant_id": 1,
            "color": "438858537",
            "description": "Wachstumsphase",
            "from_date": "2023-05-16T00:00:00.000Z",
            "until_date": "2023-06-15T00:00:00.000Z",
            "action_needed": false
          },
          {
            "id": 3,
            "plant_id": 1,
            "color": "4294198070",
            "description": "Erntezeit",
            "from_date": "2023-06-16T00:00:00.000Z",
            "until_date": "2023-07-31T00:00:00.000Z",
            "action_needed": false
          }
        ]
      },
      {
        "id": 2,
        "name": "Kopfsalat",
        "description": "Maikönig",
        "water_requirement": 0.5,
        "horizontal_space": 0.25,
        "vertical_space": 0.25,
        "image_path": "lib/assets/plants/salad-seedling-g46a52dd37_640.jpg",
        "times": [
          {
            "id": 4,
            "plant_id": 2,
            "color": "4294961979",
            "description": "Aussaat",
            "from_date": "2023-04-01T00:00:00.000Z",
            "until_date": "2023-06-01T00:00:00.000Z",
            "action_needed": true
          },
          {
            "id": 5,
            "plant_id": 2,
            "color": "438858537",
            "description": "Wachstumsphase",
            "from_date": "2023-06-02T00:00:00.000Z",
            "until_date": "2023-07-15T00:00:00.000Z",
            "action_needed": false
          },
          {
            "id": 6,
            "plant_id": 2,
            "color": "4294198070",
            "description": "Erntezeit",
            "from_date": "2023-07-16T00:00:00.000Z",
            "until_date": "2023-08-31T00:00:00.000Z",
            "action_needed": false
          }
        ]
      }
    ]''', 200);

    return mockResponse;
  }

  @override
  Future<http.Response> getPlant(int id) async {
    if (id == 1) {
      return http.Response('''{
    "id": 1,
    "name": "Tomate",
    "description": "",
    "water_requirement": 0.8,
    "horizontal_space": 0.6,
    "vertical_space": 0.8,
    "image_path": "lib/assets/plants/tomatoes-gc17bf34c6_640.jpg",
    "times": [
    {
    "id": 1,
    "plant_id": 1,
    "color": "4294961979",
    "description": "Aussaat",
    "from_date": "2023-04-01T00:00:00.000Z",
    "until_date": "2023-05-15T00:00:00.000Z",
    "action_needed": true
    },
    {
    "id": 2,
    "plant_id": 1,
    "color": "438858537",
    "description": "Wachstumsphase",
    "from_date": "2023-05-16T00:00:00.000Z",
    "until_date": "2023-06-15T00:00:00.000Z",
    "action_needed": false
    },
    {
    "id": 3,
    "plant_id": 1,
    "color": "4294198070",
    "description": "Erntezeit",
    "from_date": "2023-06-16T00:00:00.000Z",
    "until_date": "2023-07-31T00:00:00.000Z",
    "action_needed": false
    }
        ]
    }''', 200);
    }

    if (id == 2) {
      return http.Response(''' 
      {
        "id": 2,
        "name": "Kopfsalat",
        "description": "Maikönig",
        "water_requirement": 0.5,
        "horizontal_space": 0.25,
        "vertical_space": 0.25,
        "image_path": "lib/assets/plants/salad-seedling-g46a52dd37_640.jpg",
        "times": [
          {
            "id": 4,
            "plant_id": 2,
            "color": "4294961979",
            "description": "Aussaat",
            "from_date": "2023-04-01T00:00:00.000Z",
            "until_date": "2023-06-01T00:00:00.000Z",
            "action_needed": true
          },
          {
            "id": 5,
            "plant_id": 2,
            "color": "438858537",
            "description": "Wachstumsphase",
            "from_date": "2023-06-02T00:00:00.000Z",
            "until_date": "2023-07-15T00:00:00.000Z",
            "action_needed": false
          },
          {
            "id": 6,
            "plant_id": 2,
            "color": "4294198070",
            "description": "Erntezeit",
            "from_date": "2023-07-16T00:00:00.000Z",
            "until_date": "2023-08-31T00:00:00.000Z",
            "action_needed": false
          }
        ]
      }''', 200);
    }
    return http.Response('', 404);
  }
}
