package com.red.circle.console.adapter.app.sys;


import com.red.circle.console.app.service.app.sys.SysProductConfigV2Service;
import com.red.circle.console.infra.annotations.OpsOperationReqLog;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.order.inner.model.cmd.SysProductConfigV2Cmd;
import com.red.circle.order.inner.model.cmd.SysProductConfigV2QryCmd;
import com.red.circle.order.inner.model.dto.SysProductConfigDTO;
import com.red.circle.order.inner.model.dto.SysProductConfigV2DTO;

import java.util.List;

import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 内购产品列表 前端控制器.
 * </p>
 *
 * @author houyong
 * @since 2020-08-05
 */
@RestController
@RequestMapping("/sys/product/config")
@RequiredArgsConstructor
public class SysProductConfigV2RestController extends BaseController {

    private final SysProductConfigV2Service sysProductConfigV2Service;

    /**
     * 获取内购产品分页列表.
     */
    @GetMapping(value = "/list")
    public List<SysProductConfigV2DTO> pageSysProductConfig(SysProductConfigV2QryCmd query) {
        return sysProductConfigV2Service.listProductConfig(query);
    }

    @OpsOperationReqLog("添加内购产品")
    @PostMapping
    public void addProductConfig(@RequestBody @Validated SysProductConfigV2Cmd param) {

        param.setOptUserId(param.getReqUserId());
        sysProductConfigV2Service.add(param);
    }

    @OpsOperationReqLog("修改内购产品")
    @PutMapping
    public void updateProductConfig(@RequestBody @Validated SysProductConfigV2Cmd param) {

        param.setOptUserId(param.getReqUserId());
        sysProductConfigV2Service.update(param);
    }

    /**
     * 获得金币产品列表.
     */
    @GetMapping("/list_candy_group/{sysOrigin}")
    public List<SysProductConfigDTO> listCandyGroup(@PathVariable("sysOrigin") String sysOrigin) {
        return sysProductConfigV2Service.listCandyGroupBySysOrigin(sysOrigin);
    }
}
