package com.interplug.qcast.biz.storeFavorite;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import com.interplug.qcast.biz.storeFavorite.dto.StoreFavoriteRequest;
import com.interplug.qcast.biz.storeFavorite.dto.StoreFavoriteResponse;
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;

@Slf4j
@RestController
@RequestMapping("/api/store-favorite")
@RequiredArgsConstructor
@Tag(name = "StoreFavorite", description = "Store Favorite 관련 API")
public class StoreFavoriteController {
  private final StoreFavoriteService storeFavService;

  @Operation(description = "Store Favorite 정보를 등록/수정 한다.(동기화)")
  @PutMapping("/store-favorite-save")
  @ResponseStatus(HttpStatus.OK)
  public UserResponse setStoreFavoriteSave(@RequestBody StoreFavoriteRequest req) throws Exception {
    UserResponse userResponse = new UserResponse();

    int resultCnt = storeFavService.setStoreFavoriteSave(req);

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

    return userResponse;
  }

  @Operation(description = "User Store Favorite 목록을 조회한다.")
  @GetMapping("/list")
  @ResponseStatus(HttpStatus.OK)
  public StoreFavoriteResponse getStoreFavoriteList(@ModelAttribute StoreFavoriteRequest req)
      throws Exception {
    return storeFavService.getStoreFavoriteList(req);
  }

}
