package com.interplug.qcast.biz.mainPage;

import com.interplug.qcast.biz.mainPage.dto.MainPageResponse;
import com.interplug.qcast.biz.object.ObjectService;
import com.interplug.qcast.biz.object.dto.ObjectRequest;
import com.interplug.qcast.biz.object.dto.ObjectResponse;
import com.interplug.qcast.biz.object.dto.SaleStoreResponse;
import io.swagger.v3.oas.annotations.Operation;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/main-page")
@RequiredArgsConstructor
public class MainPageController {

  private final ObjectService objectService;

  @Operation(description = "메인 물건정보 목록을 조회한다.")
  @GetMapping("/object/{saleStoreId}/list")
  @ResponseStatus(HttpStatus.OK)
  public MainPageResponse selectObjectList(@PathVariable String saleStoreId) throws Exception {
    MainPageResponse mainPageResponse = new MainPageResponse();

    // 판매점명 조회
    SaleStoreResponse saleStoreResponse = objectService.selectSaleStoreInfo(saleStoreId);
    if (saleStoreResponse != null) {
      mainPageResponse.setSaleStoreId(saleStoreId);
      mainPageResponse.setSaleStoreName(saleStoreResponse.getSaleStoreName());
      mainPageResponse.setBusinessCharger(saleStoreResponse.getBusinessCharger());
      mainPageResponse.setBusinessChargerTel(saleStoreResponse.getBusinessChargerTel());
      mainPageResponse.setBusinessChargerMail(saleStoreResponse.getBusinessChargerMail());
    }

    // 물건정보 목록 조회
    ObjectRequest objectRequest = new ObjectRequest();
    objectRequest.setSaleStoreId(saleStoreId);
    objectRequest.setStartRow("1");
    objectRequest.setEndRow("3");

    List<ObjectResponse> objectList = objectService.selectObjectList(objectRequest);
    mainPageResponse.setObjectList(objectList);

    return mainPageResponse;
  }
}
