package com.its.op.entity.its.scrs;

import com.its.op.dto.its.scrs.TbScTodCnfgDto;
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;

/**
 * TOD 구성 Entity Class
 */
@Getter
@NoArgsConstructor//(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("TOD 구성")
@Entity
@Table(name = "TB_SC_TOD_CNFG")
@IdClass(TbScTodCnfgKey.class)
public class TbScTodCnfg implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("신호 교차로 번호")  // N NUMBER(4)
    @Id
    @Column(name = "SGNL_IXR_NMBR", nullable = false, columnDefinition = "NUMBER", length = 4)
    private Integer sgnlIxrNmbr;

    @ApiModelProperty("일반 제어용 플랜: 1~5, 시차 제어용 플랜: 6~10")  // N NUMBER(2)
    @Id
    @Column(name = "IXR_OPER_MODE", nullable = false, columnDefinition = "NUMBER", length = 2)
    private Integer ixrOperMode;

    @ApiModelProperty("시간별운영계획번호(1~16번까지있음)")  // N NUMBER(2)
    @Id
    @Column(name = "IXR_PHAS_OPER_PLAN_NMBR", nullable = false, columnDefinition = "NUMBER", length = 2)
    private Integer ixrPhasOperPlanNmbr;

    @ApiModelProperty("시간")  // Y NUMBER(2)
    @Column(name = "HH", columnDefinition = "NUMBER", length = 2)
    private Integer hh;

    @ApiModelProperty("분")  // Y NUMBER(2)
    @Column(name = "MM", columnDefinition = "NUMBER", length = 2)
    private Integer mm;

    @ApiModelProperty("주기")  // Y NUMBER(3)
    @Column(name = "CYCL", columnDefinition = "NUMBER", length = 3)
    private Integer cycl;

    @ApiModelProperty("옵셋")  // Y NUMBER(3)
    @Column(name = "OFST", columnDefinition = "NUMBER", length = 3)
    private Integer ofst;

    @ApiModelProperty("A링 1현시")  // Y NUMBER(3)
    @Column(name = "ARING_1PHAS", columnDefinition = "NUMBER", length = 3)
    private Integer aring1phas;

    @ApiModelProperty("A링 2현시")  // Y NUMBER(3)
    @Column(name = "ARING_2PHAS", columnDefinition = "NUMBER", length = 3)
    private Integer aring2phas;

    @ApiModelProperty("A링 3현시")  // Y NUMBER(3)
    @Column(name = "ARING_3PHAS", columnDefinition = "NUMBER", length = 3)
    private Integer aring3phas;

    @ApiModelProperty("A링 4현시")  // Y NUMBER(3)
    @Column(name = "ARING_4PHAS", columnDefinition = "NUMBER", length = 3)
    private Integer aring4phas;

    @ApiModelProperty("A링 5현시")  // Y NUMBER(3)
    @Column(name = "ARING_5PHAS", columnDefinition = "NUMBER", length = 3)
    private Integer aring5phas;

    @ApiModelProperty("A링 6현시")  // Y NUMBER(3)
    @Column(name = "ARING_6PHAS", columnDefinition = "NUMBER", length = 3)
    private Integer aring6phas;

    @ApiModelProperty("A링 7현시")  // Y NUMBER(3)
    @Column(name = "ARING_7PHAS", columnDefinition = "NUMBER", length = 3)
    private Integer aring7phas;

    @ApiModelProperty("A링 8현시")  // Y NUMBER(3)
    @Column(name = "ARING_8PHAS", columnDefinition = "NUMBER", length = 3)
    private Integer aring8phas;

    @ApiModelProperty("B링 1현시")  // Y NUMBER(3)
    @Column(name = "BRING_1PHAS", columnDefinition = "NUMBER", length = 3)
    private Integer bring1phas;

    @ApiModelProperty("B링 2현시")  // Y NUMBER(3)
    @Column(name = "BRING_2PHAS", columnDefinition = "NUMBER", length = 3)
    private Integer bring2phas;

    @ApiModelProperty("B링 3현시")  // Y NUMBER(3)
    @Column(name = "BRING_3PHAS", columnDefinition = "NUMBER", length = 3)
    private Integer bring3phas;

    @ApiModelProperty("B링 4현시")  // Y NUMBER(3)
    @Column(name = "BRING_4PHAS", columnDefinition = "NUMBER", length = 3)
    private Integer bring4phas;

    @ApiModelProperty("B링 5현시")  // Y NUMBER(3)
    @Column(name = "BRING_5PHAS", columnDefinition = "NUMBER", length = 3)
    private Integer bring5phas;

    @ApiModelProperty("B링 6현시")  // Y NUMBER(3)
    @Column(name = "BRING_6PHAS", columnDefinition = "NUMBER", length = 3)
    private Integer bring6phas;

    @ApiModelProperty("B링 7현시")  // Y NUMBER(3)
    @Column(name = "BRING_7PHAS", columnDefinition = "NUMBER", length = 3)
    private Integer bring7phas;

    @ApiModelProperty("B링 8현시")  // Y NUMBER(3)
    @Column(name = "BRING_8PHAS", columnDefinition = "NUMBER", length = 3)
    private Integer bring8phas;

    public TbScTodCnfgDto toDto() {
        return TbScTodCnfgDto.builder()
                .sgnlIxrNmbr(this.sgnlIxrNmbr)
                .ixrOperMode(this.ixrOperMode)
                .ixrPhasOperPlanNmbr(this.ixrPhasOperPlanNmbr)
                .hh(this.hh)
                .mm(this.mm)
                .cycl(this.cycl)
                .ofst(this.ofst)
                .aring1phas(this.aring1phas)
                .aring2phas(this.aring2phas)
                .aring3phas(this.aring3phas)
                .aring4phas(this.aring4phas)
                .aring5phas(this.aring5phas)
                .aring6phas(this.aring6phas)
                .aring7phas(this.aring7phas)
                .aring8phas(this.aring8phas)
                .bring1phas(this.bring1phas)
                .bring2phas(this.bring2phas)
                .bring3phas(this.bring3phas)
                .bring4phas(this.bring4phas)
                .bring5phas(this.bring5phas)
                .bring6phas(this.bring6phas)
                .bring7phas(this.bring7phas)
                .bring8phas(this.bring8phas)
                .build();
    }

    public TbScTodCnfg(Integer sgnlIxrNmbr, Integer ixrOperMode, Integer ixrPhasOperPlanNmbr) {
        this.sgnlIxrNmbr = sgnlIxrNmbr;
        this.ixrOperMode = ixrOperMode;
        this.ixrPhasOperPlanNmbr = ixrPhasOperPlanNmbr;
    }

    public void updateInfo(TbScTodCnfgDto.TbScTodCnfgUpdReq req) {
        this.hh = req.getHh();
        this.mm = req.getMm();
        this.cycl = req.getCycl();
        this.ofst = req.getOfst();
        this.aring1phas = req.getAring1phas();
        this.aring2phas = req.getAring2phas();
        this.aring3phas = req.getAring3phas();
        this.aring4phas = req.getAring4phas();
        this.aring5phas = req.getAring5phas();
        this.aring6phas = req.getAring6phas();
        this.aring7phas = req.getAring7phas();
        this.aring8phas = req.getAring8phas();
        this.bring1phas = req.getBring1phas();
        this.bring2phas = req.getBring2phas();
        this.bring3phas = req.getBring3phas();
        this.bring4phas = req.getBring4phas();
        this.bring5phas = req.getBring5phas();
        this.bring6phas = req.getBring6phas();
        this.bring7phas = req.getBring7phas();
        this.bring8phas = req.getBring8phas();
    }

}
