package com.zioinfo.kintex.ops;

import com.zioinfo.kintex.auth.EventAccessGuard;
import com.zioinfo.kintex.auth.EventRole;
import com.zioinfo.kintex.auth.KintexPrincipal;
import com.zioinfo.kintex.common.ApiResponse;
import com.zioinfo.kintex.ops.dto.OpsDto;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 홀 현장 운영 API (SCR-16). 홀매니저/주최자 열람.
 */
@RestController
@RequestMapping("/api/events/{eventId}/ops")
public class OpsController {

    private final OpsService service;
    private final EventAccessGuard guard;

    public OpsController(OpsService service, EventAccessGuard guard) {
        this.service = service;
        this.guard = guard;
    }

    /** GET — 홀 혼잡·HVAC·조명·주차 현황(센서 미연동 지표는 0/null). */
    @GetMapping
    public ApiResponse<OpsDto> get(@AuthenticationPrincipal KintexPrincipal principal,
                                   @PathVariable String eventId) {
        guard.requireRole(principal, eventId, EventRole.ORGANIZER, EventRole.HALL_MANAGER);
        return ApiResponse.ok(service.getOps(eventId));
    }
}
