package com.petshop.backend.controller;

import com.petshop.backend.dto.activity.ActivityLogResponse;
import com.petshop.backend.service.ActivityLogService;
import java.util.List;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/activity-logs")
@PreAuthorize("hasRole('ADMIN')")
public class ActivityLogController {

    private final ActivityLogService activityLogService;

    public ActivityLogController(ActivityLogService activityLogService) {
        this.activityLogService = activityLogService;
    }

    @GetMapping
    public ResponseEntity<List<ActivityLogResponse>> getActivityLogs(
            @RequestParam(defaultValue = "2000") int limit,
            @RequestParam(required = false) Long storeId,
            @RequestParam(required = false) String role,
            @RequestParam(required = false) String search) {
        int safeLimit = Math.min(Math.max(1, limit), 10000);
        return ResponseEntity.ok(activityLogService.getLogs(safeLimit, storeId, role, search));
    }
}
