package com.qaup.collision.pathconflict.model.entity;

import jakarta.persistence.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.Builder;

import java.time.LocalDateTime;

/**
 * 实时对象路径分配实体类
 * 对应 object_route_assignments 表，跟踪对象当前使用的路径
 * 
 * @author AI Assistant
 * @version 1.0
 * @since 2025-01-17
 */
@Entity
@Table(name = "object_route_assignments", indexes = {
    @Index(name = "idx_object_route_assignments_object_type", columnList = "object_type"),
    @Index(name = "idx_object_route_assignments_route", columnList = "assigned_route_id"),
    @Index(name = "idx_object_route_assignments_assigned_at", columnList = "assigned_at DESC")
})
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ObjectRouteAssignment {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    /**
     * 对象类型：UNMANNED_VEHICLE, AIRCRAFT, SPECIAL_VEHICLE, NORMAL_VEHICLE
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "object_type", nullable = false, length = 20)
    private ObjectType objectType;
    
    /**
     * 对象名称：车牌号或航班号
     */
    @Column(name = "object_name", nullable = false, length = 100)
    private String objectName;
    
    /**
     * 分配的路径ID
     */
    @Column(name = "assigned_route_id", nullable = false)
    private Long assignedRouteId;
    
    /**
     * 分配时间
     */
    @Column(name = "assigned_at")
    private LocalDateTime assignedAt;
    
    /**
     * 对象类型枚举
     */
    public enum ObjectType {
        UNMANNED_VEHICLE,   // 无人车
        AIRCRAFT,           // 航空器
        SPECIAL_VEHICLE,    // 特种车辆
        NORMAL_VEHICLE      // 普通车辆
    }
    
    @PrePersist
    protected void onCreate() {
        assignedAt = LocalDateTime.now();
    }
} 