package com.trade.admin.enterprise.customer.controller;

import com.trade.admin.enterprise.customer.domain.CustomerReferralCode;
import com.trade.admin.enterprise.customer.domain.SearchCustomerReferralCode;
import com.trade.admin.enterprise.customer.service.CustomerReferralCodeService;
import com.trade.common.core.domain.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Map;

/**
 * @description: 客户推荐码业务Controller
 * @Author: wanglang
 * @Date: 2024/5/30
 * @Version: 1.0
 */
@RestController
@RequestMapping("/customer/referralCode")
@Api(tags = "客户推荐码接口", value = "客户推荐码接口")
public class CustomerReferralCodeController {

    @Resource
    private CustomerReferralCodeService customerReferralCodeService;

    /**
     * 渠道推荐码配置查询列表
     */
    @GetMapping("/findList")
    @PreAuthorize("@ss.hasPermi('customer:referralCode:list')")
    public Object findBySearch(SearchCustomerReferralCode search) {
        return customerReferralCodeService.findBySearch(search);
    }

    /**
     * 新增页面-获取数据
     * 
     * @return 返回角色权限
     */
    @GetMapping(value = "/getDetailForAdd")
    public ResponseResult<Map<String, Object>> getDetailAdd() {
        return ResponseResult.success(customerReferralCodeService.getDetailForAdd());
    }

    /**
     * 新增
     * 
     * @param code 推荐码信息
     * @return true/false
     */
    @ApiOperation(value = "新增", notes = "新增推荐码信息")
    @PostMapping(value = "/doAdd")
    @PreAuthorize("@ss.hasPermi('customer:referralCode:add')")
    public ResponseResult<Boolean> add(@RequestBody @Valid CustomerReferralCode code) {
        return ResponseResult.success(customerReferralCodeService.add(code));
    }

    /**
     * 修改页面-获取数据
     */
    @ApiOperation(value = "修改页面", notes = "修改页面数据")
    @ApiImplicitParam(name = "customerReferralCodeId", value = "客户推荐码值id", dataTypeClass = Long.class, example = "1", required = true)
    @GetMapping(value = "/getDetailForUpdate")
    public ResponseResult<Map<String, Object>> getDetailForUpdate(Long customerReferralCodeId) {
        return ResponseResult.success(customerReferralCodeService.getDetailForUpdate(customerReferralCodeId));
    }

    /**
     * 修改页面
     * 
     * @param code
     * @return
     */
    @PostMapping(value = "/doUpdate")
    @ApiOperation(value = "更新", notes = "更新客户推荐码信息")
    @PreAuthorize("@ss.hasPermi('customer:referralCode:update')")
    public ResponseResult<Boolean> update(@RequestBody CustomerReferralCode code) {
        return ResponseResult.success(customerReferralCodeService.update(code));
    }

    /**
     * 禁用
     */
    @PostMapping(value = "/doDisable")
    @ApiOperation(value = "禁用", notes = "禁用客户推荐码信息")
    @ApiImplicitParam(name = "customerReferralCodeId", value = "客户推荐码值id", dataTypeClass = Long.class, example = "1", required = true)
    @PreAuthorize("@ss.hasPermi('customer:referralCode:disable')")
    public ResponseResult<Boolean> disable(Long customerReferralCodeId) {
        return ResponseResult.success(customerReferralCodeService.disable(customerReferralCodeId));
    }

    /**
     * 启用
     */
    @PostMapping(value = "/doEnable")
    @ApiOperation(value = "启用", notes = "启用客户推荐码信息")
    @ApiImplicitParam(name = "customerReferralCodeId", value = "客户推荐码值id", dataTypeClass = Long.class, example = "1", required = true)
    @PreAuthorize("@ss.hasPermi('customer:referralCode:enable')")
    public ResponseResult<Boolean> enable(Long customerReferralCodeId) {
        return ResponseResult.success(customerReferralCodeService.enable(customerReferralCodeId));
    }

    /**
     * 跳转到查看页面
     */
    @GetMapping(value = "/getDetailForView")
    @ApiOperation(value = "查看页面", notes = "查看客户推荐码信息")
    @ApiImplicitParam(name = "customerReferralCodeId", value = "客户推荐码值id", dataTypeClass = Long.class, example = "1", required = true)
    public ResponseResult<CustomerReferralCode> GetDetailForView(Long customerReferralCodeId) {
        return ResponseResult.success(customerReferralCodeService.getDetailForView(customerReferralCodeId));
    }

    /**
     * 删除推荐码
     * 
     * @param customerReferralCodeId
     * @return true:删除成功；false：删除失败
     */
    @PostMapping("/doDelete")
    @ApiOperation(value = "删除推荐码", notes = "删除推荐码")
    @ApiImplicitParam(name = "customerReferralCodeId", value = "客户推荐码值id", dataTypeClass = Long.class, example = "1", required = true)
    @PreAuthorize("@ss.hasPermi('customer:referralCode:delete')")
    public ResponseResult<Boolean> delete(Long customerReferralCodeId) {
        return ResponseResult.success(customerReferralCodeService.delete(customerReferralCodeId));
    }

    /**
     * 查询推荐码有没有被占用
     *
     * @param customerReferralCodeId
     * @return true:删除成功；false：删除失败
     */
    @GetMapping("/doOccupied")
    @ApiOperation(value = "查询推荐码有没有被占用", notes = "查询推荐码有没有被占用")
    @ApiImplicitParam(name = "customerReferralCodeId", value = "客户推荐码值id", dataTypeClass = Long.class, example = "1", required = true)
    public ResponseResult<Boolean> occupied(Long customerReferralCodeId) {
        return ResponseResult.success(customerReferralCodeService.occupied(customerReferralCodeId));
    }
}
