package com.oqpo.api.web.dto.response.pomng.pchReq;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.oqpo.api.entity.loanmng.LoanMgntBaseInfoEntity;
import com.oqpo.api.entity.oper.UserMngEntity;
import com.oqpo.api.entity.pomng.PchReqBaseInfoEntity;
import com.oqpo.api.entity.pomng.PchReqDtlPtclEntity;
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 PchReqInitInfoResponse {

    @ApiModelProperty(value = "로그인 소속 브랜드아이디") private String brandId;
    @ApiModelProperty(value = "로그인 소속 브랜드명") private String brandNm;
    @ApiModelProperty(value = "로그인 소속 매장아이디") private String storeId;
    @ApiModelProperty(value = "로그인 소속 매장명") private String storeNm;
    @ApiModelProperty(value = "권한타입코드") private String authTpCd;
    @ApiModelProperty(value = "정산타입") private String loanDvsn;
    @ApiModelProperty(value = "정산타입명") private String loanDvsnNm;
    @ApiModelProperty(value = "구매가능금액") private long ordUseAmt;
    @ApiModelProperty(value = "매장고유여신번호") private String loanMgntUnqNo;
    @ApiModelProperty(value = "구매요청구분 (매장구매 PD01 브랜드 PD03 ") private String pchReqDvsn;


    public static PchReqInitInfoResponse toDTO(UserMngEntity uEntity, LoanMgntBaseInfoEntity loanEntity) {
        if (uEntity == null) return null;
        return PchReqInitInfoResponse.builder()
                .brandId(uEntity.getBrandId() == null ? "" :uEntity.getBrandId())
                .brandNm(uEntity.getBrandNm() == null ? "" :uEntity.getBrandNm())
                .storeId(uEntity.getStoreId() == null ? "" :uEntity.getStoreId())
                .storeNm(uEntity.getStoreNm() == null ? "" :uEntity.getStoreNm())
                .authTpCd(uEntity.getAuthTpCd() == null ? "" : uEntity.getAuthTpCd())
                .ordUseAmt(loanEntity == null ? 0 : loanEntity.getOrdUseAmt())
                .loanDvsn(loanEntity == null ?  "" : loanEntity.getLoanDvsn() == null ? "" : loanEntity.getLoanDvsn())
                .loanDvsnNm(loanEntity == null ?  "" : loanEntity.getLoanDvsnNm() == null ? "" : loanEntity.getLoanDvsnNm())
                .loanMgntUnqNo(loanEntity == null ?  "" : loanEntity.getLoanMgntUnqNo() == null ? "" : loanEntity.getLoanMgntUnqNo())
                .pchReqDvsn(uEntity.getStoreId() == null || "".equals(uEntity.getStoreId()) ? "PD03" : "PD01")
                .build();
    }

}
