package com.erp.tenant.entity.customer;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.erp.tenant.entity.common.BaseEntity;

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

/**
 * 客户实体
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("customers")
public class Customer extends BaseEntity {

    @TableId(type = IdType.AUTO)
    private Long id;

    // ==================== 基本信息 ====================
    @TableField("customer_code")
    private String customerCode;

    private String name;

    /** 联系人 */
    private String contact;

    /** 手机号 */
    private String phone;

    /** 座机 */
    private String tel;

    /** 邮箱 */
    private String email;

    /** 地址 */
    private String address;

    // ==================== 等级和分类 ====================
    /** 客户等级 */
    @TableField("level")
    private String level;

    /** 客户分类 */
    private String category;

    // ==================== 账务信息 ====================
    /** 应收余额 */
    @TableField("receivable_balance")
    private BigDecimal receivableBalance;

    /** 累计消费 */
    @TableField("total_consumed")
    private BigDecimal totalConsumed;

    /** 信用额度 */
    @TableField("credit_limit")
    private BigDecimal creditLimit;

    // ==================== 状态 ====================
    /** 状态：1-正常，0-禁用 */
    private Integer status;

    /** 最后下单时间 */
    @TableField("last_order_at")
    private LocalDateTime lastOrderAt;

    // ==================== 备注 ====================
    private String remark;

    // ==================== 辅助方法 ====================
    public String getStatusText() {
        return status != null && status == 1 ? "正常" : "禁用";
    }

    public boolean isActive() {
        return status != null && status == 1;
    }
}
