package com.its.op.entity.its.rse;

import com.its.op.dto.its.rse.TbRseSectRltnLinkDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

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

/**
 * RSE 구간 링크구성 정보 Entity Class
 */
@Getter
@NoArgsConstructor//(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("RSE 구간 링크구성 정보")
@Entity
@Table(name = "TB_RSE_SECT_RLTN_LINK")
@IdClass(TbRseSectRltnLinkKey.class)
public class TbRseSectRltnLink implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("RSE 구간 아이디")  // N NUMBER(10)
    @Id
    @Column(name = "RSE_SECT_ID", nullable = false, columnDefinition = "NUMBER", length = 10)
    private Long rseSectId;

    @ApiModelProperty("링크ID")  // N NUMBER(10)
    @Id
    @Column(name = "LINK_ID", nullable = false, columnDefinition = "NUMBER", length = 10)
    private Long linkId;

    @ApiModelProperty("링크 순서")  // Y NUMBER(2)
    @Column(name = "LINK_ORD", columnDefinition = "NUMBER", length = 2)
    private Integer linkOrd;

    public TbRseSectRltnLinkDto toDto() {
        return TbRseSectRltnLinkDto.builder()
                .rseSectId(this.rseSectId)
                .linkId(this.linkId)
                .linkOrd(this.linkOrd)
                .build();
    }

    public TbRseSectRltnLink(Long rseSectId, Long linkId) {
        this.rseSectId = rseSectId;
        this.linkId = linkId;
    }

    public void updateInfo(TbRseSectRltnLinkDto.TbRseSectRltnLinkUpdReq req) {
        this.linkOrd = req.getLinkOrd();
    }

}
