package com.erp.controller;

import com.erp.dto.ApiResponse;
import com.erp.service.UserOverrideService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping("/api/overrides")
@RequiredArgsConstructor
public class UserOverrideController {

    private final UserOverrideService userOverrideService;

    @GetMapping
    public ResponseEntity<ApiResponse<Map<String, Object>>> getUserOverride(
            @RequestAttribute("user_id") String userId,
            @RequestParam String card_id) {
        Map<String, Object> params = new HashMap<>();
        params.put("user_id", userId);
        params.put("card_id", card_id);
        Map<String, Object> result = userOverrideService.getUserOverride(params);
        return ResponseEntity.ok(ApiResponse.success(result));
    }

    @PutMapping
    public ResponseEntity<ApiResponse<Void>> upsertUserOverride(
            @RequestAttribute("user_id") String userId,
            @RequestBody Map<String, Object> body) {
        body.put("user_id", userId);
        userOverrideService.upsertUserOverride(body);
        return ResponseEntity.ok(ApiResponse.success(null, "저장 완료"));
    }

    @DeleteMapping
    public ResponseEntity<ApiResponse<Void>> deleteUserOverride(
            @RequestAttribute("user_id") String userId,
            @RequestParam String card_id) {
        Map<String, Object> params = new HashMap<>();
        params.put("user_id", userId);
        params.put("card_id", card_id);
        userOverrideService.deleteUserOverride(params);
        return ResponseEntity.ok(ApiResponse.success(null, "삭제 완료"));
    }
}
