package ch.pizzalemon.android.api;

import java.util.HashMap;

import ch.pizzalemon.android.model.AddNewAddressResponseModel;
import ch.pizzalemon.android.model.AddProductToBasketResponseModel;
import ch.pizzalemon.android.model.AddressModel;
import ch.pizzalemon.android.model.AppVersionModel;
import ch.pizzalemon.android.model.CampaignBannerModel;
import ch.pizzalemon.android.model.CampaignModel;
import ch.pizzalemon.android.model.GeneralCouponModel;
import ch.pizzalemon.android.model.PersonalCouponModel;
import ch.pizzalemon.android.model.CountryModel;
import ch.pizzalemon.android.model.DeleteAddressResponseModel;
import ch.pizzalemon.android.model.PaymentMethodsResponseModel;
import ch.pizzalemon.android.model.PaymentTokenModel;
import ch.pizzalemon.android.model.RemoveProductFromCartResponseModel;
import ch.pizzalemon.android.model.ShippingMethodModel;
import ch.pizzalemon.android.model.StoreInfoModel;
import ch.pizzalemon.android.model.CityModel;
import ch.pizzalemon.android.model.StoreModel;
import ch.pizzalemon.android.model.StoreShiftModel;
import ch.pizzalemon.android.model.WelcomeMessageModel;
import ch.pizzalemon.android.model.ZoneModel;
import ch.pizzalemon.android.model.cart.CartInfoModel;
import ch.pizzalemon.android.model.CategoryModel;
import ch.pizzalemon.android.model.history.OrderHistoryModel;
import ch.pizzalemon.android.model.UserModel;
import ch.pizzalemon.android.model.history.OrderHistoryProductModel;
import ch.pizzalemon.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.Path;
import retrofit2.http.Query;
import retrofit2.http.Url;

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

public interface ApiInterface {


    @GET("{storeName}" + ApiEndPoints.API_GET_ALL_CATEGORIES)
    Call<ResponseArray<CategoryModel>> getAllCategories(@Path("storeName") String storeName);

    @GET("{storeName}" + ApiEndPoints.API_GET_IGNORED_CATEGORY_IDS)
    Call<ResponseArray<Integer>> getIgnoredCategoryIds(@Path("storeName") String storeName);

    @GET("{storeName}" + ApiEndPoints.API_GET_PIZZA_CATEGORY_IDS)
    Call<ResponseArray<Integer>> getPizzaCategoryIds(@Path("storeName") String storeName);

    @FormUrlEncoded
    @POST("{storeName}" + ApiEndPoints.API_REGISTER)
    Call<ResponseObject<UserModel>> register(@Path("storeName") String storeName,
                                             @FieldMap HashMap<String, Object> body);

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

    @FormUrlEncoded
    @POST("{storeName}" + ApiEndPoints.API_LOGOUT)
    Call<ResponseObject> logout(@Path("storeName") String storeName,
                                @Field("token") String customerToken);

    @GET("{storeName}" + ApiEndPoints.API_GET_ORDER_HISTORY)
    Call<ResponseArray<OrderHistoryModel>> getOrderHistory(@Path("storeName") String storeName,
                                                           @Query("token") String token);

    /*
    // OK
    @POST
    Call<ResponseObject<CartInfoModel>> getCartProducts(@Url String url);

    // OK
    @FormUrlEncoded
    @POST
    Call<ResponseObject<CartInfoModel>> getCartProductsForCommission(@Url String url,
                                                                     @Field("payment_method") String paymentMethodCode,
                                                                     @Field("shipping_method") String shippingMethodCode);

    @FormUrlEncoded
    @POST
    Call<ResponseObject<CartInfoModel>> getCartProductsWithCoupon(@Url String url,
                                                                  @FieldMap HashMap<String, Object> body);
    */

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

    @GET("{storeName}" + ApiEndPoints.API_GET_CLEAR_CART)
    Call<ResponseObject> clearCart(@Path("storeName") String storeName,
                                   @Query("token") String token);

    @GET("{storeName}" + ApiEndPoints.API_GET_PRODUCTS_BY_CATEGORY)
    Call<ResponseArray<MenuProductModel>> getProductsByCategory(@Path("storeName") String storeName,
                                                                @Query("category_id") String categoryId);

    @FormUrlEncoded
    @POST("{storeName}" + ApiEndPoints.API_GET_PRODUCT)
    Call<ResponseArray<MenuProductModel>> getProductById(@Path("storeName") String storeName,
                                                         @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.
    // OK
    @POST
    Call<ResponseObject<AddProductToBasketResponseModel>> addProductsToBasket(@Url String url,
                                                                              @Body RequestBody body);
    @GET("{storeName}" + ApiEndPoints.API_GET_SHIPPING_METHODS)
    Call<ResponseArray<ShippingMethodModel>> getShippingMethods(@Path("storeName") String storeName,
                                                                @Query("token") String token);

    @GET("{storeName}" + ApiEndPoints.API_GET_CUSTOMER_ADDRESSES)
    Call<ResponseArray<AddressModel>> getCustomerAddresses(@Path("storeName") String storeName,
                                                           @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("{storeName}" + ApiEndPoints.API_GET_PAYMENT_METHODS)
    Call<ResponseObject<PaymentMethodsResponseModel>> getPaymentMethods(@Path("storeName") String storeName,
                                                                        @Query("token") String token);

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

    @FormUrlEncoded
    @POST("{storeName}" + ApiEndPoints.API_CHECK_UPDATE)
    Call<ResponseObject<AppVersionModel>> checkUpdate(@Path("storeName") String storeName,
                                                      @FieldMap HashMap<String, Object> body);

    @GET("{storeName}" + ApiEndPoints.API_GET_WELCOME_MESSAGE)
    Call<ResponseObject<WelcomeMessageModel>> getWelcomeMessage(@Path("storeName") String storeName);

    @FormUrlEncoded
    @POST("{storeName}" + ApiEndPoints.API_FORGOT_PASSWORD)
    Call<ResponseObject> forgotPassword(@Path("storeName") String storeName,
                                        @Field("email") String emailAddress);

    @GET("{storeName}" + ApiEndPoints.API_GET_CITY_LIST)
    Call<ResponseArray<CityModel>> getCityList(@Path("storeName") String storeName);

    @GET("{storeName}" + ApiEndPoints.API_GET_COUNTRY_LIST)
    Call<ResponseArray<CountryModel>> getCountryList(@Path("storeName") String storeName);

    @FormUrlEncoded
    @POST("{storeName}" + ApiEndPoints.API_GET_ZONE_LIST)
    Call<ResponseArray<ZoneModel>> getZoneList(@Path("storeName") String storeName,
                                               @Field("country_id") String countryId);

    @GET("{storeName}" + ApiEndPoints.API_GET_CUSTOMER_PROFILE)
    Call<ResponseObject<UserModel>> getCustomerProfile(@Path("storeName") String storeName,
                                                       @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("{storeName}" + ApiEndPoints.API_GET_STORE_INFO)
    Call<ResponseObject<StoreInfoModel>> getStoreInfo(@Path("storeName") String storeName);

    @FormUrlEncoded
    @POST
    Call<ResponseArray<OrderHistoryProductModel>> getOrderProductList(@Url String url,
                                                                      @Field("order_id") String orderId);
    @FormUrlEncoded
    @POST
    Call<ResponseObject<GeneralCouponModel>> checkGeneralCoupon(@Url String url,
                                                                @Field("coupon") String couponCode);

    @FormUrlEncoded
    @POST
    Call<ResponseObject<PersonalCouponModel>> checkPersonalCoupon(@Url String url,
                                                                  @Field("voucher") String couponCode);

    @GET("{storeName}" + ApiEndPoints.API_CHECK_CAMPAIGN_PIZZAPASS)
    Call<ResponseObject<CampaignModel>> checkPizzaPassCampaign(@Path("storeName") String storeName,
                                                               @Query("token") String token);

    @GET("{storeName}" + ApiEndPoints.API_CHECK_DELIVERY_TIME)
    Call<ResponseObject<Boolean>> checkDeliveryTime(@Path("storeName") String storeName,
                                                    @Query("shipping_method_code") String shippingMethodCode);

    @FormUrlEncoded
    @POST("{storeName}" + ApiEndPoints.API_CHECK_DELIVERY_TIME)
    Call<ResponseObject<Boolean>> checkDeliveryTimeWithDateAndTime(@Path("storeName") String storeName,
                                                                   @Field("delivery_date") String deliveryDateAndTime,
                                                                   @Field("shipping_method_code") String shippingMethodCode);

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

    @GET(ApiEndPoints.API_GET_STORE_LIST)
    Call<ResponseArray<StoreModel>> getStoreList();

    @GET(ApiEndPoints.API_GET_SESSION_ID)
    Call<ResponseObject<String>> getSessionId();

    @GET("{storeName}" + ApiEndPoints.API_GET_DELIVERY_TIME_OF_STORE)
    Call<ResponseObject<StoreShiftModel>> getDeliveryTimeOfStore(@Path("storeName") String storeName,
                                                                 @Query("shipping_method_code") String shippingMethodCode);

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

    @GET
    Call<ResponseObject<PaymentTokenModel>> createBraintreePaymentToken(@Url String url);

    @GET(ApiEndPoints.API_GET_CAMPAIGN_BANNERS)
    Call<ResponseArray<CampaignBannerModel>> getCampaignBanners();

    @GET("{storeName}" + ApiEndPoints.API_GET_PERSONAL_COUPONS)
    Call<ResponseArray<PersonalCouponModel>> getPersonalCouponList(@Path("storeName") String storeName,
                                                                   @Query("token") String token);

}
