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

import com.fasterxml.jackson.annotation.JsonInclude;
import com.oqpo.api.entity.oper.FileEntity;
import com.oqpo.api.entity.oper.NticeEntity;
import com.oqpo.api.web.dto.response.session.SessionResponse;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import java.util.List;
import java.util.stream.Collectors;

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

    @ApiModelProperty(value = "가맹점아이디")
    private String afflShopId;

    @ApiModelProperty(value = "가맹점명")
    private String afflShopNm;

    @ApiModelProperty(value = "브랜드아이디")
    private String brandId;

    @ApiModelProperty(value = "브랜드명")
    private String brandNm;

    @ApiModelProperty(value = "공지번호")
    private String nticeNo;

    @ApiModelProperty(value = "공지제목")
    private String nticeTitl;

    @ApiModelProperty(value = "공지내용")
    private String nticeDesc;

    @ApiModelProperty(value = "타겟구분")
    private String targetCd;

    @ApiModelProperty(value = "타겟명")
    private String targetNm;

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

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

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

    @ApiModelProperty(value = "view카운트")
    private Integer viewCnt;

    @ApiModelProperty(value = "파일번호")
    private String fileNo;

    @ApiModelProperty(value = "브랜드대상여부")
    private String brandChk;

    @ApiModelProperty(value = "매장대상여부")
    private String shopChk;

    @ApiModelProperty(value = "공급사대상여부")
    private String supplyChk;

    @ApiModelProperty(value = "파일번호")
    private List<FileInfo> fileNoList;

    public static NticeResponse toDTO(NticeEntity entity, List<FileEntity> fileInfoList) {
        if (entity == null) return null;
        return NticeResponse.builder()
                .nticeNo(entity.getNticeNo())
                .afflShopId(entity.getAfflShopId())
                .afflShopNm(entity.getAfflShopNm())
                .brandId(entity.getBrandId())
                .brandNm(entity.getBrandNm())
                .nticeTitl(entity.getNticeTitl() == null ? "" : entity.getNticeTitl())
                .nticeDesc(entity.getNticeDesc() == null ? "" : entity.getNticeDesc())
                .targetCd(entity.getTargetCd())
                .targetNm(entity.getTargetNm())
                .delYn(entity.getDelYn())
                .notiStDay(entity.getNotiStDay())
                .notiEdDay(entity.getNotiEdDay())
                .fileNo(entity.getFileNo() == null ? "" : entity.getFileNo())
                .fileNoList(fileInfoList.stream()
                        .map(m -> FileInfo.builder()
                                .fileNo(m.getFileNo())
                                .fileSeq(m.getFileSeq())
                                .filePath(m.getFilePath())
                                .fileNm(m.getFileNm())
                                .fileOrgNm(m.getFileOrgNm())
                                .build())
                        .collect(Collectors.toList()))
                .viewCnt(entity.getViewCnt())
                .brandChk(entity.getBrandChk() == null ? "N" : entity.getBrandChk())
                .shopChk(entity.getShopChk() == null ? "N" : entity.getShopChk())
                .supplyChk(entity.getSupplyChk() == null ? "N" : entity.getSupplyChk())
                .build();
    }

    @Getter
    @Builder
    @AllArgsConstructor(access = AccessLevel.PROTECTED)
    static class FileInfo {
        @ApiModelProperty(value = "파일번호")
        private String fileNo;

        @ApiModelProperty(value = "파일순번")
        private Integer fileSeq;

        @ApiModelProperty(value = "파일경로")
        private String filePath;

        @ApiModelProperty(value = "파일명")
        private String fileNm;

        @ApiModelProperty(value = "원파일명")
        private String fileOrgNm;
    }
}

