package com.fs.hisStore.controller;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.hisStore.domain.FsStoreProductTagScrm;
import com.fs.hisStore.service.IFsStoreProductTagScrmService;
import com.fs.hisStore.vo.FsStoreProductTagListVO;
import com.fs.hisStore.vo.FsStoreTagProductVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品标签管理
 */
@RestController
@RequestMapping("/store/store/storeProductTag")
public class FsStoreProductTagScrmController extends BaseController {

    @Autowired
    private IFsStoreProductTagScrmService productTagService;

    @PreAuthorize("@ss.hasPermi('store:storeProductTag:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsStoreProductTagScrm query) {
        startPage();
        List<FsStoreProductTagListVO> list = productTagService.selectListVOPage(query);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('store:storeProductTag:query')")
    @GetMapping("/products/{tagId}")
    public TableDataInfo listProductsByTagId(@PathVariable Long tagId) {
        startPage();
        List<FsStoreTagProductVO> list = productTagService.selectProductsByTagId(tagId);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('store:storeProductTag:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return AjaxResult.success(productTagService.selectById(id));
    }

    @PreAuthorize("@ss.hasPermi('store:storeProductTag:add')")
    @Log(title = "商品标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsStoreProductTagScrm entity) {
        return toAjax(productTagService.insert(entity));
    }

    @PreAuthorize("@ss.hasPermi('store:storeProductTag:edit')")
    @Log(title = "商品标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsStoreProductTagScrm entity) {
        return toAjax(productTagService.update(entity));
    }

    @PreAuthorize("@ss.hasPermi('store:storeProductTag:remove')")
    @Log(title = "商品标签", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(productTagService.deleteByIds(ids));
    }
}
