package com.erp.waybill.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

/**
 * 运单状态跟踪实体
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("waybill_status")
public class WaybillStatus {

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

    /**
     * 运单号
     */
    private String waybillNo;

    /**
     * 快递公司编码
     */
    private String carrier;

    /**
     * 状态：pending-待揽收，in_transit-运输中，out_for_delivery-派送中，
     *       signed-已签收，rejected-拒收，returned-退回，exception-异常
     */
    private String status;

    /**
     * 当前地点
     */
    private String location;

    /**
     * 状态描述
     */
    private String description;

    /**
     * 最后轨迹时间
     */
    private LocalDateTime lastTraceTime;

    /**
     * 签收时间
     */
    private LocalDateTime signedTime;

    /**
     * 签收人姓名
     */
    private String receiverName;

    /**
     * 签收人电话
     */
    private String receiverPhone;

    /**
     * 租户ID
     */
    private Long tenantId;

    /**
     * 创建时间
     */
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createdAt;

    /**
     * 更新时间
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updatedAt;

    // ==================== 辅助方法 ====================

    public String getStatusLabel() {
        return switch (this.status) {
            case "pending" -> "待揽收";
            case "in_transit" -> "运输中";
            case "out_for_delivery" -> "派送中";
            case "signed" -> "已签收";
            case "rejected" -> "拒收";
            case "returned" -> "退回";
            case "exception" -> "异常";
            default -> this.status;
        };
    }

    public boolean isTerminal() {
        return "signed".equals(this.status) || "rejected".equals(this.status) || "returned".equals(this.status);
    }
}
