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

import com.cpop.core.base.R;
import com.cpop.core.service.CoreService;
import com.cpop.core.utils.SpringUtils;
import com.cpop.oam.business.bo.MallStaffBo;
import com.cpop.oam.business.service.OamMallService;
import com.cpop.system.business.vo.BrandListVo;
import com.cpop.oam.business.vo.MallStaffPageVo;
import com.cpop.system.business.service.BrandService;
import com.mybatisflex.core.paginate.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author DB
 * @createTime 2023/11/09 14:40
 * @description
 */
@RestController
@Api(tags = "商城管理模块")
@RequestMapping("/backstage/oamMall")
public class BackstageOamMallController {
    @Autowired
    private OamMallService oamMallService;

    /**
     * @descriptions 查询商城管理员分页列表
     * @author DB
     * @date 2023/11/09 15:33
     * @param brandIds 品牌id集合
     * @param name 姓名
     * @return: com.cpop.core.base.R<com.mybatisflex.core.paginate.Page<com.cpop.oam.business.vo.MallStaffPageVo>>
     */
    @PreAuthorize("@aps.hasPermission('mall:admin:list')")
    @ApiOperation("查询商城管理员分页列表")
    @GetMapping("/getMallStaffPage")
    public R<Page<MallStaffPageVo>> getMallStaffPage(String brandIds, String name) {
        Page<MallStaffPageVo> page = oamMallService.getMallStaffPage(brandIds, name);
        return R.ok(page);
    }

    /**
     * @descriptions 查询品牌列表
     * @author DB
     * @date 2023/11/10 11:45
     * @return: com.cpop.core.base.R<java.util.List<com.cpop.system.business.vo.BrandListVo>>
     */
    @ApiOperation("查询品牌列表")
    @GetMapping("/getBrandList")
    public R<List<BrandListVo>> getBrandList() {
        List<BrandListVo> list = SpringUtils.getBean(BrandService.class).queryChain().listAs(BrandListVo.class);
        return R.ok(list);
    }

    /**
     * @descriptions 用户名是否存在
     * @author DB
     * @date 2023/11/10 12:03
     * @param username 用户名
     * @param id id
     * @param userType 用户类型
     * @return: com.cpop.core.base.R<java.lang.Void>
     */
    @ApiOperation("用户名是否存在")
    @GetMapping("/isAccountExist")
    public R<Void> isAccountExist(@ApiParam("用户名") String username, @ApiParam("userId") String id, @ApiParam("用户类型") String userType) {
        SpringUtils.getBean(CoreService.class).isAccountExist(username, id, userType);
        return R.ok();
    }

    /**
     * @descriptions 新增管理员
     * @author DB
     * @date 2023/09/08 14:04
     * @param bo 请求参数
     * @return com.jambox.core.base.R<java.lang.Void>
     */
    @ApiOperation("新增管理员")
    @PostMapping("/insertAdmin")
    public R<Void> insertAdmin(@RequestBody @Validated MallStaffBo bo) {
        oamMallService.insertAdmin(bo);
        return R.ok();
    }

    /**
     * @descriptions 删除管理员
     * @author DB
     * @date 2023/11/10 14:33
     * @param id 主键
     * @return: com.cpop.core.base.R<java.lang.Void>
     */
    @ApiOperation("删除管理员")
    @DeleteMapping("/removeAdmin/{id}")
    public R<Void> removeAdmin(@PathVariable String id) {
        oamMallService.removeAdmin(id);
        return R.ok();
    }
}
