package com.zfire.mall.manager.controller.manage.product.price;

import com.zfire.mall.manager.enums.StatusEnum;
import com.zfire.mall.manager.exception.RemoteServiceException;
import com.zfire.mall.manager.helper.ResponseHelper;
import com.zfire.mall.manager.logic.manage.product.price.PriceSaleTypeRelaLogic;
import com.zfire.mall.manager.plus.entity.PriceSaleTypeRela;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@Api(value = "价格与销售类型对应关系", tags ={"价格与销售类型对应关系"} )
@RequestMapping(value = "/price-sales-rela", produces = "application/json; charset=utf-8")
public class PriceSaleTypeRelaController {

    @Resource
    PriceSaleTypeRelaLogic priceSaleTypeRelaLogic;

    @ApiOperation(value = "价格与销售类型对应关系-详情")
    @GetMapping("/detail")
    public ResponseHelper<PriceSaleTypeRela> detail(
            @ApiParam(value = "价格与销售类型对应关系id", required = true) @RequestParam String priceSaleTypeRelaId
    ) throws Exception {
        PriceSaleTypeRela priceSaleTypeRela = priceSaleTypeRelaLogic.detail(priceSaleTypeRelaId);
        return ResponseHelper.success(priceSaleTypeRela);
    }

    @ApiOperation(value = "价格与销售类型对应关系-新增")
    @PostMapping("/add")
    public ResponseHelper add(
            @ApiParam(required = true, value = "产品套机对应关系") @RequestBody PriceSaleTypeRela priceSaleTypeRela
    ) throws Exception {
        priceSaleTypeRelaLogic.add(priceSaleTypeRela);
        return ResponseHelper.success();
    }

    @ApiOperation(value = "价格与销售类型对应关系-编辑")
    @PostMapping("/edit")
    public ResponseHelper edit(
            @ApiParam(required = true, value = "价格与销售类型对应关系") @RequestBody PriceSaleTypeRela priceSaleTypeRela
    ) throws Exception {
        priceSaleTypeRelaLogic.edit(priceSaleTypeRela);
        return ResponseHelper.success();
    }

    @PostMapping("/status/update")
    @ApiOperation("价格与销售类型对应关系-修改状态")
    public ResponseHelper updateStatus(
            @ApiParam(value = "价格类型id",required = true) @RequestParam String priceSaleTypeRelaId,
            @ApiParam(value = "true:有效  false:无效",required = true) @RequestParam StatusEnum status
    ) throws RemoteServiceException {
        priceSaleTypeRelaLogic.updateStatus(priceSaleTypeRelaId, status);
        return ResponseHelper.success();
    }

    @ApiOperation(value = "价格与销售类型对应关系-删除")
    @PostMapping("/del")
    public ResponseHelper del(
            @ApiParam(required = true, value = "价格与销售类型对应关系id") @RequestBody List<String> ids
    ) throws Exception {
        priceSaleTypeRelaLogic.del(ids);
        return ResponseHelper.success();
    }
}
