import 'package:dio/dio.dart';
import 'package:farm_tpf/custom_model/CropPlot.dart';
import 'package:farm_tpf/custom_model/Device.dart';
import 'package:farm_tpf/custom_model/EnvironmentParameter.dart';
import 'package:farm_tpf/custom_model/Harvest.dart';
import 'package:farm_tpf/custom_model/LocationUnit.dart';
import 'package:farm_tpf/custom_model/Supply.dart';
import 'package:farm_tpf/custom_model/UpdateNoti.dart';
import 'package:farm_tpf/custom_model/WaterType.dart';
import 'package:farm_tpf/custom_model/account.dart';
import 'package:farm_tpf/custom_model/password.dart';
import 'package:farm_tpf/custom_model/user.dart';
import 'package:farm_tpf/custom_model/user_request.dart';
import 'package:farm_tpf/models/index.dart';
import 'package:farm_tpf/utils/const_common.dart';
import 'package:retrofit/retrofit.dart';

part 'rest_client.g.dart';

@RestApi(baseUrl: ConstCommon.baseUrl)
abstract class RestClient {
  factory RestClient(Dio dio, {String baseUrl}) = _RestClient;

  @POST("/api/authenticate")
  Future<User> login(@Body() UserRequest userRequest);

  @GET("/api/account")
  Future<Account> getMe();

  @POST("/api/account/reset-password/init")
  Future<void> forgotPassword(@Body() String email);

  @POST("/api/account/reset-password/finish")
  Future<void> resetPassword(@Body() Password password);

  @POST("/api/account/change-password")
  Future<void> changePassword(@Body() Password password);

  @PUT("/api/update-my-profile")
  Future<Account> updateProfile(@Body() Account account);

  @GET("/api/list-supplies-in-warehouses/{type}?q={query}")
  Future<List<Supply>> getSupplies(@Path() String type,
      {@DioOptions() Options options, @Path() String query = ""});

  //Common
  @PUT("/api/update-fcmToken")
  Future<void> updateFcmToken(@Body() String token);

  @PUT("/api/delete-fcmToken")
  Future<void> deleteFcmToken(@Body() String token);

  //Plot
  @GET(
      "/api/_search/tb-crops?page={page}&size={size}&sort=id,asc&query={query}")
  Future<List<Crop>> getPlots(
      {@Path() int page = 0, @Path() int size = 20, @Path() String query = ""});

  @GET("/api/listActivityTypesOther")
  Future<List<ActionType>> getActionTypes({@DioOptions() Options options});

  @GET("/api/water-types")
  Future<List<WaterType>> getWaterTypes({@DioOptions() Options options});

  @GET("/api/tb-harvests")
  Future<List<Harvest>> getHarvests({@DioOptions() Options options});

  @GET("/api/listDeviceForActivity")
  Future<List<Device>> getDeviceForActivity({@DioOptions() Options options});

  @PUT("/api/notifications/update-all")
  Future<void> updateAllNotification(@Body() String status);

  @PUT("/api/notifications/update")
  Future<void> updateNoti(@Body() UpdateNoti updateNoti);

  @GET("/api/tb-countries?page={page}&size={size}&query={query}&&sort=name,ASC")
  Future<List<LocationUnit>> getCountries(
      {@Path() int page = 0,
      @Path() int size = 400,
      @Path() String query = '',
      @DioOptions() Options options});

  @GET(
      "/api/tb-cities-by-country/{countryId}?page={page}&size={size}&query={query}&&sort=name,ASC")
  Future<List<LocationUnit>> getProvinces(@Path() int countryId,
      {@Path() int page = 0,
      @Path() int size = 20,
      @Path() String query = '',
      @DioOptions() Options options});

  @GET(
      "/api/tb-districts-by-city/{provinceId}?page={page}&size={size}&query={query}&&sort=name,ASC")
  Future<List<LocationUnit>> getDistricts(@Path() int provinceId,
      {@Path() int page = 0,
      @Path() int size = 20,
      @Path() String query = '',
      @DioOptions() Options options});

  @GET(
      "/api/tb-wards-by-district/{districtId}?page={page}&size={size}&query={query}&&sort=name,ASC")
  Future<List<LocationUnit>> getWards(@Path() int districtId,
      {@Path() int page = 0,
      @Path() int size = 20,
      @Path() String query = '',
      @DioOptions() Options options});

  //Crop
  @GET(
      "/api/tb-crops-detail-for-app/{cropId}?page={page}&size={size}&sort=executeDate,DESC")
  Future<CropPlot> getCropDetail(@Path() int cropId,
      {@Path() int page = 0, @Path() int size = 20});

  @GET(
      "/api/tb-crops-scan-qrCode/{cropCode}?page={page}&size={size}&sort=executeDate,DESC")
  Future<CropPlot> getCropDetailByCode(@Path() String cropCode,
      {@Path() int page = 0, @Path() int size = 20});

  @PUT("/api/tb-crops")
  Future<void> updateCrop(@Body() TbCropDTO crop);
  //Device
  @GET("/api/listDeviceOfUserCustomers?query={query}")
  Future<List<Device>> getDevices({@Path() String query});
  //Get environment parameter
  @GET("/api/list-environment-updates-display/{cropId}?page={page}&size={size}")
  Future<List<EnvironmentParameter>> getEnvironmentParameters(
      @Path() int cropId,
      {@Path() int page = 0,
      @Path() int size = 20});
}
