package com.sckw.order.controller;

import com.sckw.core.web.response.HttpResult;
import com.sckw.order.model.vo.req.AddWantBuyParam;
import com.sckw.order.model.vo.req.UpdateWantBuyParam;
import com.sckw.order.serivce.KwpWantBuyService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @desc: 求购controller
 * @author: yzc
 * @date: 2023-07-24 14:44
 */
@RestController
@RequestMapping(value = "/kwoWantBuy")
@RequiredArgsConstructor
public class KwpWantBuyController {

    private final KwpWantBuyService kwpWantBuyService;

    /**
     * @desc: 新增求购草稿
     * @author: yzc
     * @date: 2023-07-24 16:42
     * @Param addWantBuyParam:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @PostMapping(value = "/addDraft", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult addDraft(@RequestBody AddWantBuyParam addWantBuyParam) {
        kwpWantBuyService.addDraft(addWantBuyParam);
        return HttpResult.ok("新增求购草稿成功");
    }

    /**
     * @desc: 新增求购上架
     * @author: yzc
     * @date: 2023-07-24 16:43
     * @Param addWantBuyParam:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @PostMapping(value = "/addShelves", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult addShelves(@RequestBody @Validated AddWantBuyParam addWantBuyParam) {
        kwpWantBuyService.addShelves(addWantBuyParam);
        return HttpResult.ok("新增求购上架成功");
    }

    /**
     * @desc: 求购详情
     * @author: yzc
     * @date: 2023-07-24 16:45
     * @Param id:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @GetMapping("/detail")
    public HttpResult detail(@RequestParam Long id) {
        return HttpResult.ok(kwpWantBuyService.detail(id));
    }

    @PostMapping(value = "/update", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult update(@RequestBody @Validated UpdateWantBuyParam updateWantBuyParam) {
        kwpWantBuyService.update(updateWantBuyParam);
        return HttpResult.ok("求购修改成功!");
    }

}
