package com.gxwebsoft.cms.entity;

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

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

/**
 * 推荐人关系实体（全民推荐）
 *
 * @author 科技小王子
 * @since 2026-04-14
 */
@Data
@TableName("lead_referral")
@Schema(name = "LeadReferral", description = "推荐人关系")
public class LeadReferral implements Serializable {

    private static final long serialVersionUID = 1L;

    @Schema(description = "推荐关系ID")
    @TableId(type = IdType.AUTO)
    private Integer referralId;

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

    @Schema(description = "被推荐的客资ID")
    private Integer referredLeadId;

    @Schema(description = "推荐码")
    private String referralCode;

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

    @Schema(description = "推荐状态: 0待确认 1有效 2无效 3已结算")
    private Integer referralStatus;

    @Schema(description = "客户姓名")
    private String customerName;

    @Schema(description = "客户电话")
    private String customerPhone;

    @Schema(description = "结算时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime settlementTime;

    @Schema(description = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    // ========== 关联信息（非数据库字段）==========
    @Schema(description = "推荐人昵称")
    private String referrerName;

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

    @Schema(description = "客资状态")
    private Integer leadStatus;

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

    // ========== 状态常量 ==========
    public static final int STATUS_PENDING = 0;   // 待确认
    public static final int STATUS_VALID = 1;     // 有效
    public static final int STATUS_INVALID = 2;    // 无效
    public static final int STATUS_SETTLED = 3;   // 已结算

    public String getStatusText() {
        if (this.referralStatus == null) return "";
        return switch (this.referralStatus) {
            case STATUS_PENDING -> "待确认";
            case STATUS_VALID -> "有效";
            case STATUS_INVALID -> "无效";
            case STATUS_SETTLED -> "已结算";
            default -> "";
        };
    }
}
