package shop.alien.store.controller;

import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.store.StoreLabel;
import shop.alien.store.service.StoreLabelService;

import java.util.List;

/**
 * 二期-门店标签Controller
 *
 * @author ssk
 * @since 2024-12-05
 */
@Slf4j
@Api(tags = {"二期-门店标签"})
@ApiSort(3)
@CrossOrigin
@RestController
@RequestMapping("/label")
@RequiredArgsConstructor
public class StoreLabelController {

    private final StoreLabelService storeLabelService;

    @ApiOperation("获取门店标签")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParams({@ApiImplicitParam(name = "storeId", value = "门店id", dataType = "Long", paramType = "query", required = true)})
    @GetMapping("/getByStoreId")
    public R<List<StoreLabel>> getByStoreId(Long storeId) {
        log.info("StoreLabelController.getByStoreId?id={}", storeId);
        return R.data(storeLabelService.getStoreLabel(storeId));
    }

    @ApiOperation("新增或修改门店标签")
    @ApiOperationSupport(order = 2)
    @PostMapping("/saveOrUpdate")
    public R<Boolean> saveOrUpdate(@RequestBody StoreLabel storeLabel) {
        log.info("StoreLabelController.saveOrUpdate?storeBusinessInfo={}", storeLabel);
        if (storeLabelService.saveOrUpdate(storeLabel)) {
            if (null != storeLabel.getId()) {
                return R.success("修改成功");
            }
            return R.success("新增成功");
        }
        return R.fail("新增失败");
    }

    @ApiOperation(value = "删除门店标签")
    @ApiOperationSupport(order = 3)
    @PostMapping("/delete")
    public R<String> delete(@RequestBody List<Integer> ids) {
        log.info("StoreLabelController.delete?ids={}", ids);
        if (storeLabelService.removeByIds(ids)) {
            return R.success("删除成功");
        }
        return R.fail("删除失败");
    }

}
