package com.interplug.qcast.biz.user;

import com.interplug.qcast.biz.user.dto.StoreRequest;
import com.interplug.qcast.biz.user.dto.UserRequest;
import com.interplug.qcast.biz.user.dto.UserResponse;
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.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/user")
@RequiredArgsConstructor
@Tag(name = "UserController", description = "User 관련 API")
public class UserController {
    private final UserService userService;

    @Operation(description = "판매점 정보를 등록/수정 한다.(동기화)")
    @PutMapping("/store-save")
    @ResponseStatus(HttpStatus.OK)
    public UserResponse setStoreSave(@RequestBody StoreRequest storeReq) throws Exception {
        UserResponse userResponse = new UserResponse();

        int resultCnt = userService.setStoreSave(storeReq);

        if (resultCnt > 0) userResponse.setCode("200");
        else userResponse.setCode("500");

        return userResponse;
    }

    @Operation(description = "user 정보를 등록/수정 한다.(동기화)")
    @PutMapping("/user-save")
    @ResponseStatus(HttpStatus.OK)
    public UserResponse setUserSave(@RequestBody List<UserRequest> userReqList) throws Exception {
        UserResponse userResponse = new UserResponse();

        int resultCnt = userService.setUserSave(userReqList);

        if (resultCnt > 0) userResponse.setCode("200");
        else userResponse.setCode("500");

        return userResponse;
    }

    @Operation(description = "판매점 Sap 정보를 등록/수정 한다.(동기화)")
    @PutMapping("/store-sap-info-save")
    @ResponseStatus(HttpStatus.OK)
    public UserResponse setStoreSapCdSave(@RequestBody StoreRequest storeReq) throws Exception {
        UserResponse userResponse = new UserResponse();

        int resultCnt = userService.setStoreSapCdSave(storeReq);

        if (resultCnt > 0) userResponse.setCode("200");
        else userResponse.setCode("500");

        return userResponse;
    }
}
