package com.wzj.soopin.goods.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzj.soopin.goods.convert.BrandConvert;
import com.wzj.soopin.goods.domain.bo.BrandBo;
import com.wzj.soopin.goods.domain.bo.ProductCategoryBo;
import com.wzj.soopin.goods.domain.entity.Brand;
import com.wzj.soopin.goods.domain.entity.ProductCategory;
import com.wzj.soopin.goods.domain.vo.BrandVO;
import com.wzj.soopin.goods.domain.vo.ProductCategoryVO;
import com.wzj.soopin.goods.service.impl.BrandServiceImpl;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.web.core.BaseController;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * 品牌管理Controller
 *
 * @author zcc
 * @date 2022-11-28
 */
@Tag(name ="品牌管理接口列表")
@RestController
@RequestMapping("/pms/brand")
@RequiredArgsConstructor
public class BrandController extends BaseController {

    private final BrandServiceImpl service;
    private final BrandConvert convert;


    @Tag(name ="所有品牌管理列表")
    @PostMapping("list")
    public R<Page<BrandVO>> list(@RequestBody BrandBo query, Page<Brand> page) {
        Page<Brand> brandPage = service.page(page,query.toWrapper());
        return R.ok(convert.toVO(brandPage));
    }

    @Tag(name ="所有品牌管理列表")
    @PostMapping("page")
    public R<List<BrandVO>> list(@RequestBody BrandBo query) {
        List<Brand> productCategoryList = service.list(query.toWrapper());
        return R.ok(convert.toVO(productCategoryList));
    }


    @Tag(name ="导出品牌管理列表")
    @Log(title = "品牌管理", businessType = BusinessType.EXPORT)
    @PostMapping("export")
    public R<String> export(BrandBo query) {
        List<Brand> list = service.list(query.toWrapper());
        ExcelUtil<BrandVO> util = new ExcelUtil<>(BrandVO.class);
        return R.ok(util.writeExcel(convert.toVO(list), "品牌管理数据"));
    }


    @Tag(name ="获取品牌管理详细信息")
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") Long id) {
        return R.ok(service.getById(id));
    }

    @Tag(name ="新增品牌管理")
    @Log(title = "品牌管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R add(@RequestBody Brand brand) {
        return R.ok(service.save(brand));
    }

    @Tag(name ="修改品牌管理")
    @Log(title = "品牌管理", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public R edit(@RequestBody Brand brand) {
        return R.ok(service.updateById(brand));
    }

    @Tag(name ="删除品牌管理")
    @Log(title = "品牌管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public R remove(@PathVariable Long id) {
       return R.ok(service.removeById(id));
    }
}
