package com.cpop.oam.business.controller.backstage;

import com.cpop.core.base.R;
import com.cpop.oam.business.bo.BrandManagerBo;
import com.cpop.oam.business.bo.BrandManagerPageBo;
import com.cpop.oam.business.service.BrandManagerService;
import com.cpop.system.business.bo.StoreListByBrandBo;
import com.cpop.system.business.entity.table.BrandTableDef;
import com.cpop.system.business.entity.table.StoreTableDef;
import com.cpop.system.business.service.BrandService;
import com.cpop.system.business.service.StoreService;
import com.cpop.system.business.vo.BrandListVo;
import com.cpop.oam.business.vo.BrandManagePageVo;
import com.cpop.system.business.vo.StoreListByBrandVo;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;

/**
 * 品牌管理员表 控制层。
 *
 * @author DB
 * @since 2023-12-07
 */
@RestController
@Api(tags = "品牌管理员表接口")
@RequestMapping("/backstage/brandManage")
public class BackstageBrandManagerController {
    @Autowired
    private BrandManagerService brandManageService;

    @Autowired
    private BrandService brandService;

    @Autowired
    private StoreService storeService;

    /**
     * 查询品牌管理员分页
     * @author DB
     * @since 2023/12/07
     * @param bo 请求参数
     * @return R<Page<BrandManagePageVo>>
     */
    @ApiOperation("查询品牌管理员分页")
    @GetMapping("/getBrandManagePage")
    @PreAuthorize("@aps.hasPermission('brandStore:brandStaff:list')")
    public R<Page<BrandManagePageVo>> getBrandManagePage(BrandManagerPageBo bo) {
        Page<BrandManagePageVo> page = brandManageService.getBrandManagerPage(bo);
        return R.ok(page);
    }

    /**
     * 查询品牌列表
     * @author DB
     * @since 2023/09/07 18:07
     * @return R<List<BrandListVo>>
     */
    @ApiOperation("查询品牌列表")
    @GetMapping("/getBrandList")
    public R<List<BrandListVo>> getBrandList(String query) {
        List<BrandListVo> list = brandService.listAs(QueryWrapper.create().and(BrandTableDef.BRAND.BRAND_NAME.like(query)), BrandListVo.class);
        return R.ok(list);
    }

    /**
     * 查询品牌列表
     * @return R<PageVo<BrandPageListVo>>
     * @author DB
     * @since 2023/6/2 17:37
     **/
    @ApiOperation("根据品牌查询校区列表")
    @PostMapping("/getStoreListByBrand")
    public R<List<StoreListByBrandVo>> getCampusListByBrand(@RequestBody StoreListByBrandBo bo) {
        List<StoreListByBrandVo> vos = storeService.listAs(QueryWrapper.create().and(StoreTableDef.STORE.BRAND_ID.in(bo.getBrandIds())), StoreListByBrandVo.class);
        return R.ok(vos);
    }

    /**
     * 删除品牌管理员
     * @author DB
     * @since 2023/12/07
     * @param id 主键
     * @return R<Void>
     */
    @ApiOperation("删除品牌管理员")
    @DeleteMapping("/removeBrandManageById/{id}")
    public R<Void> removeBrandManageById(@PathVariable String id) {
        brandManageService.removeBrandManagerById(id);
        return R.ok();
    }

    /**
     * 新增品牌管理员
     * @author DB
     * @since 2023/12/07
     * @param bo 请求
     * @return R<Void>
     */
    @ApiOperation("新增品牌管理员")
    @PostMapping("insertBrandManage")
    public R<Void> insertBrandManage(@RequestBody @Validated BrandManagerBo bo) {
        brandManageService.insertBrandManager(bo);
        return R.ok();
    }

}
