package cn.iocoder.yudao.module.app.customer.admin;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.conf.entity.BaseType;
import cn.iocoder.yudao.module.custom.entity.CustomerMain;
import cn.iocoder.yudao.module.custom.service.CustomerActiveService;
import cn.iocoder.yudao.module.custom.service.CustomerMainService;
import cn.iocoder.yudao.module.custom.vo.CustomerActiveSaveReqVO;
import cn.iocoder.yudao.module.custom.vo.CustomerMainRespVO;
import cn.iocoder.yudao.module.member.entity.MemberLevel;
import cn.iocoder.yudao.module.member.service.ActiveMainService;
import cn.iocoder.yudao.module.member.service.MemberLevelService;
import cn.iocoder.yudao.module.member.vo.ActiveMainPageReqVO;
import cn.iocoder.yudao.module.member.vo.ActiveMainRespVO;
import cn.iocoder.yudao.module.member.vo.MemberLevelPageReqVO;
import cn.iocoder.yudao.module.order.entity.RepairOrderInfo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 客户管理API
 * @author PQZ
 * @date 18:17 2024/9/24
**/
@RestController
@RequestMapping("/userClient/customer")
public class CustomerMainApi {

    @Resource
    private CustomerMainService customerMainService;
    @Resource
    private MemberLevelService levelService;
    @Resource
    private CustomerActiveService activeService;
    @Resource
    private ActiveMainService activeMainService;

    /**
     * 查询当前登录客户信息
     * @author PQZ
     * @date 17:24 2024/9/24
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<cn.iocoder.yudao.module.custom.vo.CustomerMainRespVO>
    **/
    @GetMapping("/getUserCustomer")
    @Operation(summary = "获取当前登录用户的客户信息")
    public CommonResult<CustomerMainRespVO> getUserCustomer() {
        return success(customerMainService.getUserCustomer());
    }

    @GetMapping("/allMember")
    @Operation(summary = "获得全部会员")
    public CommonResult<List<MemberLevel>> getLevelAll(MemberLevelPageReqVO pageReqVO) {
        return success(levelService.queryListAll(pageReqVO));
    }

    /**
     * 根据车辆ID反查用户信息
     *
     * @author 小李
     * @date 21:41 2024/9/24
     * @param carId 车辆ID
    **/
    @GetMapping("/getByCarId")
    @Operation(summary = "根据车辆ID反查用户信息")
    public CommonResult<?> getCustomerByCarId(@RequestParam("carId")String carId) {
        return success(customerMainService.getCustomerByCarId(carId));
    }


    /**
     * 参加活动
     *
     * @param createReqVO CustomerActiveSaveReqVO
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.String>
     * @author PQZ
     * @date 9:49 2024/9/21
     **/
    @PostMapping("/attendActive")
    @Operation(summary = "参加活动")
    public CommonResult<RepairOrderInfo> attendActive(@RequestBody CustomerActiveSaveReqVO createReqVO) {
        RepairOrderInfo orderInfo = activeService.attendActive(createReqVO);
        return success(orderInfo);
    }



    @GetMapping("/getActive")
    @Operation(summary = "获得营销活动")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<ActiveMainRespVO> getActiveMain(@RequestParam("id") String id) {
        ActiveMainRespVO activeMain = activeMainService.getActiveMain(id,false);
        return success(activeMain);
    }

    /**
     *
     * @author PQZ
     * @date 16:12 2024/9/23
     * @param pageReqVO ActiveMainPageReqVO实体
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<com.baomidou.mybatisplus.core.metadata.IPage<?>>
     **/
    @GetMapping("/activeList")
    @Operation(summary = "可参与营销活动")
    public CommonResult<List<?>> getActiveMainPage(ActiveMainPageReqVO pageReqVO) {
        return success(activeService.isJoinActive(pageReqVO));
    }
}
