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

import com.its.op.dto.its.rse.TbRseOffrSectRltnIfscDto;
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_OFFR_SECT_RLTN_IFSC")
@IdClass(TbRseOffrSectRltnIfscKey.class)
public class TbRseOffrSectRltnIfsc implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("제공 구간 아이디")  // N NUMBER(10)
    @Id
    @Column(name = "OFFR_SECT_ID", nullable = false, columnDefinition = "NUMBER", length = 10)
    private Long offrSectId;

    @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;

    public TbRseOffrSectRltnIfscDto toDto() {
        return TbRseOffrSectRltnIfscDto.builder()
                .offrSectId(this.offrSectId)
                .ifscId(this.ifscId)
                .ord(this.ord)
                .build();
    }

    public TbRseOffrSectRltnIfsc(Long offrSectId, Long ifscId) {
        this.offrSectId = offrSectId;
        this.ifscId = ifscId;
    }

    public void updateInfo(TbRseOffrSectRltnIfscDto.TbRseOffrSectRltnIfscUpdReq req) {
        this.ord = req.getOrd();
    }

}
