package com.fs.company.controller.crm;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.R;
import com.fs.crm.domain.CrmCustomerLevel;
import com.fs.crm.service.ICrmCustomerLevelService;
import com.fs.his.vo.OptionsVO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/crm/customerLevel")
@AllArgsConstructor
public class CrmCustomerLevelController extends BaseController {

    private final ICrmCustomerLevelService customerLevelService;

    @GetMapping("/getCustomerLevelOption")
    public R getCustomerLevelOption(Integer status) {
        LambdaQueryWrapper<CrmCustomerLevel> wrapper = Wrappers.lambdaQuery();
        if (Objects.nonNull(status)) {
            wrapper.eq(CrmCustomerLevel::getStatus, status);
        }
        List<OptionsVO> options = customerLevelService.list(wrapper).stream().map(l -> {
            OptionsVO vo = new OptionsVO();
            vo.setDictLabel(l.getName());
            vo.setDictValue(l.getId());
            return vo;
        }).collect(Collectors.toList());
        return R.ok().put("data", options);
    }
}
