package gc.mda.signal_batch.domain.vessel.dto;

import gc.mda.signal_batch.global.util.IntegrationSignalConstants;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 통합선박 정보 DTO
 * signal.t_ship_integration_sub 테이블 매핑
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class IntegrationVessel {

    private Long intgrSeq;
    private String ais;
    private String enav;
    private String vpass;
    private String vtsAis;
    private String dMfHf;
    private String aisShipNm;
    private String enavShipNm;
    private String vpassShipNm;
    private String vtsAisShipNm;
    private String dMfHfShipNm;
    private String integrationShipTy;

    /**
     * integration_target_id 생성
     */
    public String generateIntegrationId() {
        return IntegrationSignalConstants.generateIntegrationId(
                ais, enav, vpass, vtsAis, dMfHf
        );
    }

    /**
     * 신호 타입에 해당하는 target_id 반환
     */
    public String getTargetIdBySignalType(IntegrationSignalConstants.SignalType signalType) {
        if (signalType == null) return null;

        return switch (signalType) {
            case AIS -> ais;
            case E_NAVIGATION -> enav;
            case VPASS -> vpass;
            case VTS_AIS -> vtsAis;
            case D_MF_HF -> dMfHf;
        };
    }

    /**
     * 신호 타입에 해당하는 선박명 반환
     */
    public String getShipNameBySignalType(IntegrationSignalConstants.SignalType signalType) {
        if (signalType == null) return null;

        return switch (signalType) {
            case AIS -> aisShipNm;
            case E_NAVIGATION -> enavShipNm;
            case VPASS -> vpassShipNm;
            case VTS_AIS -> vtsAisShipNm;
            case D_MF_HF -> dMfHfShipNm;
        };
    }

    /**
     * 해당 신호 타입의 데이터가 존재하는지 확인
     */
    public boolean hasSignalType(IntegrationSignalConstants.SignalType signalType) {
        String targetId = getTargetIdBySignalType(signalType);
        return targetId != null && !"0".equals(targetId) && !targetId.isEmpty();
    }
}
