package com.oqpo.api.web.dto.response.stinfo.brand;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.oqpo.api.entity.oper.FileEntity;
import com.oqpo.api.entity.oper.SaleMgrMgntEntity;
import com.oqpo.api.entity.stinfo.BrandEntity;
import com.oqpo.api.web.dto.response.oper.affl.AfflShopInfoResponse;
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 BrandInfoResponse {

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

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

    @ApiModelProperty(value = "상태코드")
    private String stCd ;

    @ApiModelProperty(value = "싱태명")
    private String stNm ;

    @ApiModelProperty(value = "브랜드타입")
    private String brandType ;

    @ApiModelProperty(value = "브랜드타입명")
    private String brandTypeNm ;

    @ApiModelProperty(value = "우편번호")
    private String zipNo;

    @ApiModelProperty(value = "주소1")
    private String addr1 ;

    @ApiModelProperty(value = "주소2")
    private String addr2 ;

    @ApiModelProperty(value = "x위도")
    private String latX;

    @ApiModelProperty(value = "y경도")
    private String longY;

    @ApiModelProperty(value = "전화번호")
    private String telNo ;

    @ApiModelProperty(value = "팩스번호")
    private String faxNo ;

    @ApiModelProperty(value = "등록일")
    private String regDt;

    @ApiModelProperty(value = "등록자")
    private String regId ;

    @ApiModelProperty(value = "이메일")
    private String emalAddr ;

    @ApiModelProperty(value = "은행코드")
    private String bnkCd ;

    @ApiModelProperty(value = "은행명")
    private String bnkCdNm ;

    @ApiModelProperty(value = "은행계좌번호")
    private String acctNo;

    @ApiModelProperty(value = "예금주명")
   private String owacNm ;

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

    @ApiModelProperty(value = "브랜드로고파일번호")
    private String brandLogoFileNo ;

    @ApiModelProperty(value = "사업자번호")
    private String bsnsRegNo ;

    @ApiModelProperty(value = "법인번호")
    private String corpRegNo;

    @ApiModelProperty(value = "오더퀸브랜드아이디")
    private String oqBrandId ;

    @ApiModelProperty(value = "시스템등록일")
    private String sysRegDttm;

    @ApiModelProperty(value = "시스템등록자")
    private String sysRegId;

    @ApiModelProperty(value = "시스템변경일")
    private String sysChgDttm;

    @ApiModelProperty(value = "시스템변경자")
    private String sysChgId;

    @ApiModelProperty(value = "로그파일 정보")
    private List<BrandInfoResponse.FileLogInfo> fileLogNoList;

    public static BrandInfoResponse toDTO(BrandEntity entity, List<FileEntity>  fileLogInfoList) {
        if (entity == null) return null;
        return BrandInfoResponse.builder()
                .brandId(entity.getBrandId())
                .brandNm(entity.getBrandNm())
                .stCd(entity.getStCd())
                .stNm(entity.getStNm() == null ? "" :entity.getStNm())
                .brandType(entity.getBrandType() == null ? "" :entity.getBrandType())
                .brandTypeNm(entity.getBrandTypeNm() == null ? "" :entity.getBrandTypeNm())
                .zipNo(entity.getZipNo() == null ? "" :entity.getZipNo())
                .addr1(entity.getAddr1() == null ? "" :entity.getAddr1())
                .addr2(entity.getAddr2() == null ? "" :entity.getAddr2())
                .latX(entity.getLatX() == null ? "" :entity.getLatX())
                .longY(entity.getLongY() == null ? "" :entity.getLongY())
                .telNo(entity.getTelNo() == null ? "" :entity.getTelNo())
                .faxNo(entity.getFaxNo() == null ? "" :entity.getFaxNo())
                .regDt(entity.getRegDt() == null ? "" :entity.getRegDt())
                .regId(entity.getRegId() == null ? "" :entity.getRegId())
                .emalAddr(entity.getEmalAddr() == null ? "" :entity.getEmalAddr())
                .bnkCd(entity.getBnkCd() == null ? "" :entity.getBnkCd())
                .bnkCdNm(entity.getBrandNm() == null ? "" :entity.getBrandNm())
                .acctNo(entity.getBrandNm() == null ? "" :entity.getBrandNm())
                .owacNm(entity.getOwacNm() == null ? "" :entity.getOwacNm())
                .afflShopId(entity.getAfflShopId() == null ? "" :entity.getAfflShopId())
                .brandLogoFileNo(entity.getBrandLogoFileNo() == null ? "" :entity.getBrandLogoFileNo())
                .fileLogNoList(fileLogInfoList.stream()
                        .map(m -> BrandInfoResponse.FileLogInfo.builder()
                                .fileNo(m.getFileNo())
                                .fileSeq(m.getFileSeq())
                                .filePath(m.getFilePath())
                                .fileNm(m.getFileNm())
                                .fileOrgNm(m.getFileOrgNm())
                                .build())
                        .collect(Collectors.toList()))
                .bsnsRegNo(entity.getBsnsRegNo() == null ? "" :entity.getBsnsRegNo())
                .corpRegNo(entity.getCorpRegNo() == null ? "" :entity.getCorpRegNo())
                .oqBrandId(entity.getOqBrandId() == null ? "" :entity.getOqBrandId())
                .sysRegDttm(entity.getSysRegDttm())
                .sysRegId(entity.getRegId())
                .sysChgDttm(entity.getSysChgDttm())
                .sysChgId(entity.getSysChgId())
                .build();
    }

    @Getter
    @Builder
    @AllArgsConstructor(access = AccessLevel.PROTECTED)
    static class FileLogInfo {
        @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;
    }
}
