package ch.pizzalink.android.api;

import java.util.HashMap;

import ch.pizzalink.android.model.AddNewAddressResponseModel;
import ch.pizzalink.android.model.AddProductToBasketResponseModel;
import ch.pizzalink.android.model.AddressModel;
import ch.pizzalink.android.model.AppVersionModel;
import ch.pizzalink.android.model.CountryModel;
import ch.pizzalink.android.model.DeleteAddressResponseModel;
import ch.pizzalink.android.model.PaymentMethodsResponseModel;
import ch.pizzalink.android.model.RemoveProductFromCartResponseModel;
import ch.pizzalink.android.model.ShippingMethodModel;
import ch.pizzalink.android.model.StoreInfoModel;
import ch.pizzalink.android.model.CityModel;
import ch.pizzalink.android.model.ZoneModel;
import ch.pizzalink.android.model.cart.CartInfoModel;
import ch.pizzalink.android.model.CategoryModel;
import ch.pizzalink.android.model.OrderHistoryModel;
import ch.pizzalink.android.model.UserModel;
import ch.pizzalink.android.model.menu.MenuProductModel;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.Field;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Query;
import retrofit2.http.Url;

/**
 * Created by cimenmus on 04/02/2017.
 */

public interface ApiInterface {

    @GET(ApiEndPoints.API_GET_ALL_CATEGORIES)
    Call<ResponseArray<CategoryModel>> getAllCategories();

    @GET(ApiEndPoints.API_GET_IGNORED_CATEGORI_IDS)
    Call<ResponseArray<Integer>> getIgnoredCategoryIds();

    @FormUrlEncoded
    @POST(ApiEndPoints.API_REGISTER)
    Call<ResponseObject<UserModel>> register(@FieldMap HashMap<String, Object> body);

    @FormUrlEncoded
    @POST(ApiEndPoints.API_LOGIN)
    Call<ResponseObject<UserModel>> login(@Field("email") String email, @Field("password") String password);

    @FormUrlEncoded
    @POST(ApiEndPoints.API_LOGOUT)
    Call<ResponseObject> logout(@Field("token") String customerToken);

    @GET(ApiEndPoints.API_GET_ORDER_HISTORY)
    Call<ResponseArray<OrderHistoryModel>> getOrderHistory(@Query("token") String token);

    @GET(ApiEndPoints.API_GET_CART_PRODUCTS)
    Call<ResponseObject<CartInfoModel>> getCartProducts(@Query("token") String token);

    @GET(ApiEndPoints.API_GET_CLEAR_CART)
    Call<ResponseObject> clearCart(@Query("token") String token);

    @GET(ApiEndPoints.API_GET_PRODUCTS_BY_CATEGORY)
    Call<ResponseArray<MenuProductModel>> getProductsByCategory(@Query("category_id") String categoryId);

    @FormUrlEncoded
    @POST(ApiEndPoints.API_GET_PRODUCT)
    Call<ResponseArray<MenuProductModel>> getProductById(@Field("product_id") int productId);

    /*
     * Bu projedeki post servisler bizden form-data bekliyor. Bu serviste @FormUrlEncoded yapınca ve
     * body'i @FieldMap HashMap<String, Object> body olarak verince, body içindeki alanlar
     * encode ediliyor, mesela body içindeki "[" karakteri "%5D" ye falan dönüşüyor, dolayısı ile servis bunları okuyamıyor.
     * Bu sebeple body olarak RequestBody verdim ve servisi çağırırken bod içindeki alanları FormBody olarak ekledim.
     */
    @POST
    Call<ResponseObject<AddProductToBasketResponseModel>> addProductsToBasket(@Url String url,
                                                                              @Body RequestBody body);
    @GET(ApiEndPoints.API_GET_SHIPPING_METHODS)
    Call<ResponseArray<ShippingMethodModel>> getShippingMethods(@Query("token") String token);

    @GET(ApiEndPoints.API_GET_CUSTOMER_ADDRESSES)
    Call<ResponseArray<AddressModel>> getCustomerAddresses(@Query("token") String token);

    @FormUrlEncoded
    @POST
    Call<ResponseObject<AddNewAddressResponseModel>> addNewAddress(@Url String url,
                                                                           @FieldMap HashMap<String, Object> body);
    @FormUrlEncoded
    @POST
    Call<ResponseObject<DeleteAddressResponseModel>> deleteAddress(@Url String url,
                                                                   @Field("address_id") String addressId);
    @GET(ApiEndPoints.API_GET_PAYMENT_METHODS)
    Call<ResponseObject<PaymentMethodsResponseModel>> getPaymentMethods(@Query("token") String token);

    @FormUrlEncoded
    @POST
    Call<ResponseObject<Integer>> createOrder(@Url String url, @FieldMap HashMap<String, Object> body);

    @FormUrlEncoded
    @POST(ApiEndPoints.API_CHECK_UPDATE)
    Call<ResponseObject<AppVersionModel>> checkUpdate(@FieldMap HashMap<String, Object> body);

    @FormUrlEncoded
    @POST(ApiEndPoints.API_FORGOT_PASSWORD)
    Call<ResponseObject> forgotPassword(@Field("email") String emailAddress);

    @GET(ApiEndPoints.API_GET_CITY_LIST)
    Call<ResponseArray<CityModel>> getCityList();

    @GET(ApiEndPoints.API_GET_COUNTRY_LIST)
    Call<ResponseArray<CountryModel>> getCountryList();

    @FormUrlEncoded
    @POST(ApiEndPoints.API_GET_ZONE_LIST)
    Call<ResponseArray<ZoneModel>> getZoneList(@Field("country_id") String countryId);

    @GET(ApiEndPoints.API_GET_CUSTOMER_PROFILE)
    Call<ResponseObject<UserModel>> getCustomerProfile(@Query("token") String token);

    @FormUrlEncoded
    @POST
    Call<ResponseObject> updatePassword(@Url String url, @FieldMap HashMap<String, Object> body);

    @FormUrlEncoded
    @POST
    Call<ResponseObject<UserModel>> updateProfile(@Url String url, @FieldMap HashMap<String, Object> body);

    @FormUrlEncoded
    @POST
    Call<ResponseObject<RemoveProductFromCartResponseModel>> removeProductFromCart(@Url String url,
                                                                                   @FieldMap HashMap<String, Object> body);
    @GET(ApiEndPoints.API_GET_STORE_INFO)
    Call<ResponseObject<StoreInfoModel>> getStoreInfo();

}
