package com.gxwebsoft.cms.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 客资管理扩展实体
 * 在CmsContactLead基础上扩展派单、推荐人等字段
 *
 * @author 科技小王子
 * @since 2026-04-14
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("cms_contact_lead")
@Schema(name = "CustomerLeadEntity", description = "客资管理扩展实体")
public class CustomerLeadEntity extends CmsContactLead implements Serializable {

    private static final long serialVersionUID = 1L;

    @Schema(description = "被分配的业务员用户ID")
    private Integer assignedUserId;

    @Schema(description = "推荐人用户ID")
    private Integer referrerUserId;

    @Schema(description = "推荐费金额")
    private BigDecimal referralFee;

    @Schema(description = "推荐费是否已支付 0否 1是")
    private Integer referralFeePaid;

    @Schema(description = "推荐人分成比例%")
    private BigDecimal referrerShare;

    @Schema(description = "派单时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime dispatchTime;

    @Schema(description = "派单管理员ID")
    private Integer dispatchAdminId;

    @Schema(description = "跟进次数")
    private Integer followCount;

    @Schema(description = "最后跟进时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime lastFollowTime;

    @Schema(description = "预约时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime appointmentTime;

    @Schema(description = "成交金额")
    private BigDecimal dealAmount;

    @Schema(description = "成交时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime dealTime;

    @Schema(description = "来源类型: form表单 website网站 miniapp小程序 referral推荐人 admin录入")
    private String sourceType;

    // ========== 关联用户信息（非数据库字段）==========
    @Schema(description = "被分配的业务员昵称")
    private String assignedUserName;

    @Schema(description = "被分配的业务员真实姓名")
    private String assignedRealName;

    @Schema(description = "被分配的业务员电话")
    private String assignedUserPhone;

    @Schema(description = "推荐人昵称")
    private String referrerName;

    @Schema(description = "推荐人电话")
    private String referrerPhone;

    @Schema(description = "派单管理员昵称")
    private String dispatchAdminName;

    @Schema(description = "业务员跟进次数统计")
    private Integer userLeadCount;

    @Schema(description = "业务员本月成交数")
    private Integer userDealCount;

    // ========== 来源类型常量 ==========
    public static final String SOURCE_FORM = "form";       // 表单
    public static final String SOURCE_WEBSITE = "website";   // 网站
    public static final String SOURCE_MINIAPP = "miniapp";   // 小程序
    public static final String SOURCE_REFERRAL = "referral"; // 推荐人
    public static final String SOURCE_ADMIN = "admin";       // 管理员录入

    // ========== 状态常量 ==========
    public static final int STATUS_PENDING = 0;      // 待跟进
    public static final int STATUS_FOLLOWING = 1;   // 跟进中
    public static final int STATUS_DEALED = 2;     // 已成交
    public static final int STATUS_INVALID = 3;    // 无效

}
