package com.xingxi.api.controller;

import com.xingxi.api.common.BaseApiController;
import com.xingxi.api.data.domain.MercProdRequest;
import com.xingxi.api.data.domain.MercProdResponse;
import com.xingxi.api.model.*;
import com.xingxi.api.service.ProdServiceI;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/store/homepage")
public class ProdApiController extends BaseApiController {

    private final ProdServiceI prodService;

    @PostMapping("/prods")
    public MercProdListResponse getProdList(@Valid @RequestBody MercProdRequest request) {

        List<MercProdResponse> prodList = prodService.selectMercProdList(request);

        return new MercProdListResponse(prodList);
    }

    @PostMapping("/prodDetail")
    public MercProdResponse getProdDetail(@Valid @RequestBody MercProdRequest request) {

        return prodService.selectMercProdById(request.getMercProdId());

    }
}
