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.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 联系表单/销售线索
 *
 * @author 科技小王子
 * @since 2026-03-30
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Schema(name = "CmsContactLead对象", description = "联系表单/销售线索")
public class CmsContactLead implements Serializable {

    private static final long serialVersionUID = 1L;

    @Schema(description = "线索ID")
    @TableId(value = "lead_id", type = IdType.AUTO)
    private Integer leadId;

    @Schema(description = "联系人姓名", required = true)
    @NotBlank(message = "姓名不能为空")
    @Size(max = 50, message = "姓名长度不能超过50个字符")
    private String name;

    @Schema(description = "手机号", required = true)
    @NotBlank(message = "手机号不能为空")
    @Size(max = 25, message = "手机号长度不能超过25个字符")
    @Pattern(regexp = "^[+]?[0-9\\-\\s()]{6,25}$", message = "手机号格式不正确")
    private String phone;

    @Schema(description = "单位/公司名称")
    @Size(max = 100, message = "公司名称长度不能超过100个字符")
    private String company;

    @Schema(description = "交付方式: saas/private/hybrid")
    @Size(max = 20, message = "交付方式长度不能超过20个字符")
    private String delivery;

    @Schema(description = "需求描述")
    @Size(max = 1000, message = "需求描述长度不能超过1000个字符")
    private String need;

    @Schema(description = "来源渠道: web/miniapp/app")
    @Size(max = 20, message = "来源渠道长度不能超过20个字符")
    private String source;

    @Schema(description = "提交IP")
    @Size(max = 50, message = "IP长度不能超过50个字符")
    private String ip;

    @Schema(description = "跟进状态: 0待跟进 1跟进中 2已成交 3无效")
    private Integer status;

    @Schema(description = "销售备注")
    private String remarks;

    @Schema(description = "是否删除, 0否, 1是")
    @TableLogic
    private Integer deleted;

    @Schema(description = "租户ID")
    private Integer tenantId;

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

    @Schema(description = "更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    public String getStatusText() {
        if (this.status == null) return "";
        return switch (this.status) {
            case 0 -> "待跟进";
            case 1 -> "跟进中";
            case 2 -> "已成交";
            case 3 -> "无效";
            default -> "";
        };
    }
}
