package com.oqpo.api.web.dto.response.oper.pop;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.oqpo.api.entity.oper.PopEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

@Getter
@Setter
@Builder
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@JsonInclude(JsonInclude.Include.ALWAYS)
public class PopResponse {

    @ApiModelProperty(value = "팝업번호")
    private String popNo ;

    @ApiModelProperty(value = "팝업명")
    private String popNm ;

    @ApiModelProperty(value = "게시시작일")
    private String popStDay ;

    @ApiModelProperty(value = "게시종료일")
    private String popEdDay ;

    @ApiModelProperty(value = "삭제여부")
    private String delYn ;

    @ApiModelProperty(value = "팝업내용구분")
    private String popTypeCd ;

    @ApiModelProperty(value = "팝업내용구분명")
    private String popTypeNm ;

    @ApiModelProperty(value = "팝업내용")
    private String popDesc ;

    @ApiModelProperty(value = "팝업파일번호")
    private String popFileNo ;

    @ApiModelProperty(value = "노출위치")
    private String viewTargetCd ;

    @ApiModelProperty(value = "노출위치명")
    private String viewTargetNm ;

    @ApiModelProperty(value = "메뉴번호")
    private String menuNo ;

    @ApiModelProperty(value = "메뉴경로명")
    private String menuPath ;

    @ApiModelProperty(value = "팝업이미지경로")
    private String fileUrl ;

    @ApiModelProperty(value = "팝업width")
    private Integer popWidth ;

    @ApiModelProperty(value = "팝업height")
    private Integer popHeight ;

    public static PopResponse toDTO(PopEntity entity) {
        if (entity == null) return null;
        return PopResponse.builder()
                .popNo(entity.getPopNo())
                .popNm(entity.getPopNm())
                .popStDay(entity.getPopStDay())
                .popEdDay(entity.getPopEdDay())
                .delYn(entity.getDelYn())
                .popTypeCd(entity.getPopTypeCd())
                .popTypeNm(entity.getPopTypeNm())
                .popDesc(entity.getPopDesc() == null ? "" : entity.getPopDesc())
                .popFileNo(entity.getPopFileNo() == null ? "" : entity.getPopFileNo())
                .viewTargetCd(entity.getViewTargetCd())
                .viewTargetNm(entity.getViewTargetNm())
                .menuNo(entity.getMenuNo() == null || entity.getMenuNo() == 0 ? "" : entity.getMenuNo().toString())
                .menuPath(entity.getMenuPath() == null ? "" : entity.getMenuPath())
                .fileUrl(entity.getFile() == null ? "" : entity.getFile().getFilePath() == null ? "" : entity.getFile().getFilePath())
                .popWidth(entity.getPopWidth())
                .popHeight(entity.getPopHeight())
                .build();
    }
}
