package com.saas.admin.controller;

import com.saas.subscription.entity.PaymentRecord;
import com.saas.subscription.service.SubscriptionService;
import com.saas.shared.dto.common.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/admin/payments")
@RequiredArgsConstructor
@Slf4j
@Tag(name = "Admin - Payment Management", description = "Operations for viewing payments")
@PreAuthorize("hasRole('SYSTEM_ADMIN')")
public class AdminPaymentController {

    private final SubscriptionService subscriptionService;

    @GetMapping
    @Operation(summary = "Get all payments", description = "Retrieve a list of all payments across all tenants")
    public ResponseEntity<ApiResponse<List<PaymentRecord>>> getAllPayments() {
        log.info("Request to list all payments");
        List<PaymentRecord> payments = subscriptionService.getAllPayments();
        return ResponseEntity.ok(ApiResponse.success(payments, "Payments retrieved successfully"));
    }
}
