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.PriceTypeLogic;
import com.zfire.mall.manager.plus.entity.PriceType;
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-type", produces = "application/json; charset=utf-8")
public class PriceTypeController {

    @Resource
    PriceTypeLogic priceTypeLogic;

    @ApiOperation(value = "价格类型-详情")
    @GetMapping("/detail")
    public ResponseHelper<PriceType> detail(
            @ApiParam(value = "价格类型id", required = true) @RequestParam String priceTypeId) throws Exception {
        PriceType priceType = priceTypeLogic.detail(priceTypeId);
        return ResponseHelper.success(priceType);
    }

    @ApiOperation(value = "价格类型-新增")
    @PostMapping("/add")
    public ResponseHelper add(
            @ApiParam(required = true, value = "价格类型") @RequestBody PriceType priceType
    ) throws Exception {
        return ResponseHelper.success(priceTypeLogic.add(priceType));
    }

    @ApiOperation(value = "价格类型-编辑")
    @PostMapping("/edit")
    public ResponseHelper edit(
            @ApiParam(required = true, value = "价格类型") @RequestBody PriceType priceType
    ) throws Exception {
        priceTypeLogic.edit(priceType);
        return ResponseHelper.success();
    }

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

    @ApiOperation(value = "价格类型-删除")
    @PostMapping("/del")
    public ResponseHelper del(
            @ApiParam(required = true, value = "价格类型") @RequestBody List<String> ids
    ) throws Exception {
        priceTypeLogic.del(ids);
        return ResponseHelper.success();
    }
}
