package org.hzhub.crm.controller;

import lombok.RequiredArgsConstructor;
import org.hzhub.common.core.domain.R;
import org.hzhub.common.log.annotation.Log;
import org.hzhub.common.log.enums.BusinessType;
import org.hzhub.crm.domain.bo.CrmLeadFollowBo;
import org.hzhub.crm.domain.vo.CrmLeadFollowVo;
import org.hzhub.crm.service.ICrmLeadFollowService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * CRM线索跟进记录 Controller
 * 员工门户版本（无需Sa-Token权限注解，权限由Gateway控制）
 *
 * 注意：Gateway已配置 /crm/** 路由并StripPrefix=1（去除/crm前缀）
 * 所以Controller使用 /lead/follow 路径，实际对外接口为 /crm/lead/follow/**
 *
 * @author hzhub
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/lead/follow")
public class CrmLeadFollowController {

    private final ICrmLeadFollowService followService;

    /**
     * 获取跟进记录列表
     *
     * @param leadId 线索ID
     */
    @GetMapping("/{leadId}")
    public R<List<CrmLeadFollowVo>> getFollowRecords(@PathVariable Long leadId) {
        return R.ok(followService.selectFollowRecordsByLeadId(leadId));
    }

    /**
     * 添加跟进记录
     */
    @Log(title = "线索跟进", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> addFollow(@Validated @RequestBody CrmLeadFollowBo follow) {
        followService.insertFollowRecord(follow);
        return R.ok();
    }
}