package com.its.op.entity.its.vms;

import com.its.op.dto.its.vms.TbVmsIfscRltnIfscDto;
import com.its.op.entity.its.ifsc.TbIfsc;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;
import java.io.Serializable;

/**
 * VMS LINK 정보제공구간 Entity Class
 */
@Getter
@NoArgsConstructor//(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("VMS LINK 정보제공구간")
@Entity
@Table(name = "TB_VMS_IFSC_RLTN_IFSC")
@IdClass(TbVmsIfscRltnIfscKey.class)
public class TbVmsIfscRltnIfsc implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("VMS 정보제공구간 ID")  // N NUMBER(10)
    @Id
    @Column(name = "VMS_IFSC_ID", nullable = false, columnDefinition = "NUMBER", length = 10)
    private Long vmsIfscId;

    @ApiModelProperty("정보제공구간 ID")  // N NUMBER(10)
    @Id
    @Column(name = "IFSC_ID", nullable = false, columnDefinition = "NUMBER", length = 10)
    private Long ifscId;

    @ApiModelProperty("순서")  // Y NUMBER(3)
    @Column(name = "ORD", columnDefinition = "NUMBER", length = 3)
    private Integer ord;

    @ApiModelProperty("정보제공구간정보")
    @OneToOne//(fetch = FetchType.EAGER)
    @JoinColumn(insertable=false, updatable=false, name="IFSC_ID", referencedColumnName = "IFSC_ID")
    @NotFound(action = NotFoundAction.IGNORE)
    private TbIfsc ifsc;

    public TbVmsIfscRltnIfscDto toDto() {
        return TbVmsIfscRltnIfscDto.builder()
                .vmsIfscId(this.vmsIfscId)
                .ifscId(this.ifscId)
                .ord(this.ord)
                .build();
    }

    public TbVmsIfscRltnIfsc(Long vmsIfscId, Long ifscId) {
        this.vmsIfscId = vmsIfscId;
        this.ifscId = ifscId;
    }

    public void updateInfo(TbVmsIfscRltnIfscDto.TbVmsLinkIfscUpdReq req) {
        this.ord = req.getOrd();
    }

}
