package com.kbs.kbsintranett;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.util.List;
import java.util.Map;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Path;
import retrofit2.http.Multipart;
import retrofit2.http.Part;
import retrofit2.http.PartMap;
import retrofit2.http.Query;

public interface WordPressApiService {

    // --- NYHETER ---
    @GET("wp-json/wp/v2/posts?per_page=10&_embed")
    Call<List<WpPost>> getPosts();

    @GET("wp-json/wp/v2/posts?per_page=50&_embed")
    Call<List<WpPost>> getAllPosts();


    // --- AUTENTISERING & ENHET ---
    @POST("wp-json/kbs/v1/login")
    Call<LoginResponse> googleLogin(@Body LoginRequest request);

    @POST("wp-json/kbs/v1/device/register")
    Call<JsonElement> registerDevice(@Body RegisterDeviceRequest request);

    @GET("wp-json/kbs/v1/users")
    Call<List<User>> getUsersList();


    // --- KALENDER ---
    @GET("wp-json/kbs/v1/calendar/events")
    Call<List<CalendarEvent>> getCalendarEvents();

    @POST("wp-json/kbs/v1/calendar/create")
    Call<JsonElement> createCalendarEvent(@Body CreateEventRequest request);

    @POST("wp-json/kbs/v1/calendar/update")
    Call<JsonElement> updateCalendarEvent(@Body CreateEventRequest request);

    @POST("wp-json/kbs/v1/calendar/delete")
    Call<JsonElement> deleteCalendarEvent(@Body CreateEventRequest request);


    // --- SKJEMAER (GRAVITY FORMS) ---
    @GET("wp-json/kbs/v1/forms")
    Call<List<GravityForm>> getFormsList();

    @GET("wp-json/kbs/v1/forms/{id}")
    Call<GravityForm> getForm(@Path("id") int formId);

    @Multipart
    @POST("wp-json/gf/v2/forms/{id}/submissions")
    Call<JsonElement> submitMultipartForm(
            @Path("id") int formId,
            @PartMap Map<String, RequestBody> textFields,
            @Part List<MultipartBody.Part> files
    );

    @GET("wp-json/gf/v2/entries")
    Call<GravityEntryResponse> getEntries(
            @Query("form_ids") int formId,
            @Query("search") String searchJson,
            @Query("paging[page_size]") int pageSize
    );

    @GET("wp-json/gf/v2/entries/{entry_id}")
    Call<JsonElement> getSingleEntry(@Path("entry_id") String entryId);


    // --- HÅNDBOK ---
    @GET("wp-json/kbs/v1/handbook")
    Call<List<HandbookItem>> getHandbookItems();

    @GET("wp-json/kbs/v1/handbook/{id}")
    Call<HandbookPage> getHandbookPage(@Path("id") int id);

    @GET("wp-json/kbs/v1/lookup-id")
    Call<JsonObject> lookupPageId(@Query("url") String url);


    // --- OPPGAVER (SYNKRONISERING) ---
    @GET("wp-json/kbs/v1/tasks")
    Call<List<TaskItem>> getTasks();

    @POST("wp-json/kbs/v1/tasks/sync")
    Call<JsonElement> syncTasks(@Body List<TaskItem> tasks);
}