package gc.mda.kcg.master;

import jakarta.persistence.*;
import lombok.*;

import java.math.BigDecimal;
import java.time.OffsetDateTime;

/**
 * 함정(경비함) 마스터.
 * 해양경찰 소속 함정의 제원 및 현재 상태 관리.
 */
@Entity
@Table(name = "patrol_ship_master", schema = "kcg")
@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder
public class PatrolShip {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ship_id")
    private Long shipId;

    @Column(name = "ship_code", length = 20, unique = true)
    private String shipCode;

    @Column(name = "ship_name", length = 100)
    private String shipName;

    @Column(name = "ship_class", length = 50)
    private String shipClass;

    @Column(name = "tonnage")
    private BigDecimal tonnage;

    @Column(name = "max_speed_kn")
    private BigDecimal maxSpeedKn;

    @Column(name = "fuel_capacity_l")
    private BigDecimal fuelCapacityL;

    @Column(name = "base_port", length = 50)
    private String basePort;

    @Column(name = "current_status", length = 20)
    private String currentStatus;

    @Column(name = "current_lat")
    private Double currentLat;

    @Column(name = "current_lon")
    private Double currentLon;

    @Column(name = "current_zone_code", length = 30)
    private String currentZoneCode;

    @Column(name = "fuel_pct")
    private Integer fuelPct;

    @Column(name = "crew_count")
    private Integer crewCount;

    @Column(name = "is_active")
    private Boolean isActive;

    @Column(name = "updated_at")
    private OffsetDateTime updatedAt;

    @PrePersist
    void prePersist() {
        if (isActive == null) isActive = true;
        if (updatedAt == null) updatedAt = OffsetDateTime.now();
    }

    @PreUpdate
    void preUpdate() {
        updatedAt = OffsetDateTime.now();
    }
}
