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

import jakarta.persistence.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.Builder;
import org.locationtech.jts.geom.LineString;

import java.time.LocalTime;
import java.time.LocalDateTime;

/**
 * 交通路径实体类
 * 对应 transport_routes 表，存储航空器和无人车的预定路径
 * 
 * @author AI Assistant
 * @version 1.0
 * @since 2025-01-17
 */
@Entity
@Table(name = "transport_routes", indexes = {
    @Index(name = "idx_transport_routes_type", columnList = "route_type"),
    @Index(name = "idx_transport_routes_status", columnList = "status")
})
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class TransportRoute {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    /**
     * 路径名称
     */
    @Column(name = "route_name", nullable = false, length = 100)
    private String routeName;
    
    /**
     * 路径类型：AIRCRAFT, UNMANNED_VEHICLE, SPECIAL_VEHICLE, NORMAL_VEHICLE
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "route_type", nullable = false, length = 20)
    private RouteType routeType;
    
    /**
     * 路径描述
     */
    @Column(name = "description", length = 500)
    private String description;
    
    /**
     * 路径几何形状 (LineString)
     */
    @Column(name = "route_geometry", nullable = false, columnDefinition = "geometry(LineString,4326)")
    private LineString routeGeometry;
    
    /**
     * 最大速度 (km/h)
     */
    @Column(name = "max_speed_kph")
    private Double maxSpeedKph;
    
    /**
     * 典型速度 (km/h)
     */
    @Column(name = "typical_speed_kph")
    private Double typicalSpeedKph;
    
    /**
     * 活跃时间开始
     */
    @Column(name = "active_time_start")
    private LocalTime activeTimeStart;
    
    /**
     * 活跃时间结束
     */
    @Column(name = "active_time_end")
    private LocalTime activeTimeEnd;
    
    /**
     * 路径状态
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "status", length = 20)
    @Builder.Default
    private RouteStatus status = RouteStatus.ACTIVE;
    
    /**
     * 是否双向
     */
    @Column(name = "is_bidirectional")
    @Builder.Default
    private Boolean isBidirectional = false;
    
    /**
     * 创建者
     */
    @Column(name = "created_by", length = 50)
    private String createdBy;
    
    /**
     * 更新者
     */
    @Column(name = "updated_by", length = 50)
    private String updatedBy;
    
    /**
     * 创建时间
     */
    @Column(name = "created_at")
    private LocalDateTime createdAt;
    
    /**
     * 更新时间
     */
    @Column(name = "updated_at")
    private LocalDateTime updatedAt;
    
    /**
     * 路径类型枚举
     */
    public enum RouteType {
        AIRCRAFT,           // 航空器路径
        UNMANNED_VEHICLE,   // 无人车路径
        SPECIAL_VEHICLE,    // 特种车辆路径
        NORMAL_VEHICLE      // 普通车辆路径
    }
    
    /**
     * 路径状态枚举
     */
    public enum RouteStatus {
        ACTIVE,      // 活跃
        INACTIVE,    // 非活跃
        MAINTENANCE  // 维护中
    }
    
    @PrePersist
    protected void onCreate() {
        createdAt = LocalDateTime.now();
        updatedAt = LocalDateTime.now();
    }
    
    @PreUpdate
    protected void onUpdate() {
        updatedAt = LocalDateTime.now();
    }
} 