package org.example.petshopdesktop.api.endpoints;

import com.fasterxml.jackson.core.type.TypeReference;
import org.example.petshopdesktop.api.ApiClient;
import org.example.petshopdesktop.api.dto.activity.ActivityLogResponse;

import java.time.LocalDate;
import java.util.List;

public class ActivityLogApi {
    private static final ActivityLogApi INSTANCE = new ActivityLogApi();
    private final ApiClient apiClient;

    private ActivityLogApi() {
        this.apiClient = ApiClient.getInstance();
    }

    public static ActivityLogApi getInstance() {
        return INSTANCE;
    }

    public List<ActivityLogResponse> getActivityLogs(int limit, LocalDate startDate, LocalDate endDate) throws Exception {
        StringBuilder path = new StringBuilder("/api/v1/activity-logs?limit=").append(limit);
        if (startDate != null) path.append("&startDate=").append(startDate);
        if (endDate != null) path.append("&endDate=").append(endDate);
        String response = apiClient.getRawResponse(path.toString());
        return apiClient.getObjectMapper().readValue(
            response,
            new TypeReference<List<ActivityLogResponse>>() {}
        );
    }

    public List<ActivityLogResponse> getActivityLogs(int limit) throws Exception {
        return getActivityLogs(limit, null, null);
    }
}
