package com.style24.persistence.domain;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.style24.core.support.session.TscSession;
import com.style24.core.support.util.CryptoUtils;
import com.style24.core.support.util.MaskingUtils;
import com.style24.persistence.TscBaseDomain;
import com.style24.persistence.TscPageRequest;

import lombok.Data;

/**
 * 취/반/교 Domain
 * 
 * @author jsh77b
 * @since 2021. 01. 18
 */
@SuppressWarnings("serial")
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class OrderChange extends TscBaseDomain {
	List<Order> cancelReqList;
	private Integer ordNo;
	private Integer ordDtlNo;
	private Integer custNo;
	private Integer userNo;
	private String orderNm;
	private String ordNm;
	private String ordPhnno;
	private String ordEmail;
	private String delvFeeCd;
	private String delvFeeCdGrp;
	private Integer delvAddrSq;
	
	private Integer ordChgSq;
	private String chgGb;
	private String chgReason;
	private String chgReasonNm;
	private String chgMemo;
	private String chgerNm;
	private String chgerPhnno;
	private String chgerTelno;
	private String chgerEmail;
	private String chgerZipcode;
	private String chgerBaseAddr;
	private String chgerDtlAddr;
	private String chgerRtnMemo;
	private int addPayCost;
	private int addPayAmt;
	private String wdInvoiceNo;
	private String wdInvoiceSendYn;
	private String wdStdt;
	private String wdEddt;
	private String shipCompCd;
	private String shipCompNm;
	private String wdBfSendYn;
	private String npayChangeHoldYn;

	private int chgQty;
	private String chgStat;
	private String chgStatNm;
	private String whMemo;
	
	private String accountNo;
	private String encodedAccountNo;
	private String accountNm;
	private String bankCd;
	private String bankNm;
	
	public String getAccountNo() {
		this.accountNo = CryptoUtils.decryptAES(this.accountNo);
		return this.accountNo;
	}

	public void encryptData () {
		this.encodedAccountNo = CryptoUtils.encryptAES(this.accountNo);
	}

	private String allCanYn;
	private String lastCanYn;
	private String allCanYnBeforePayment;

	private Boolean isCustomer;
	
	private int[] ordDtlNoArr;
	private int[] cnclRtnReqQtyArr;
	private String[] chgOptCdArr;
	private String[] chgOptCd2Arr;
	private String ordDtlNos;
	private String chgQtys;

	private List<Integer> ordDtlNoList = new ArrayList<>();
	private List<Integer> cnclRtnReqQtyList = new ArrayList<>();
	
	private String wdGb;
	private String wdTargetYn;
	private String recipNm;
	private String recipEmail;
	private String recipZipcode;
	private String recipBaseAddr;
	private String recipDtlAddr;
	private String recipPhnno;
	private String recipTelno;
	private String delvMemo;

	private int chgOrdDtlNo;
	private String completeDt;
	private String wdShipState;
	private String wdReasonCd;
	private String wdStateDt;
	private String delYn;
	
	private String reqGbn;
	private String sellGb;

	private Integer ordDtlItemSq;
	private String itemCd;
	private String optCd;
	private String optCd1;
	private String optCd2;
	private String colorNm;
	private String goodsType;
	private String goodsTypeNm;
	private String itemNm;
	private String goodsStat;
	private String chgOptCd;
	private String chgOptCd2;
	private String chgCurrStockQty;
	private String chgSoldoutYn;
	private String selfGoodsYn;
	private String[] itemNmArr;
	private String[] colorNmArr;
	private String[] optCdArr;
	private String[] optCd1Arr;
	private String[] optCd2Arr;
	private String[] currStockQtyArr;
	private String[] soldoutYnArr;
	private int[] ordChgSqArr;

	private String ipAddress;

	// 교환 옵션 변경
	private List<ChgOption> chgOptionList;

	@Data
	public class ChgOption {
		private int[] ordDtlItemSq;
		private List<ChgOptCd2> chgOptCd2List;
	}
	
	@Data
	public class ChgOptCd2 {
		private String chtOptCd2;
		private int qty;
	}

	// 취반교 리스트
	private String ordDt;							// 주문일시
	private String ordDate;							// 주문시간
	private String ordTime;							// 주문시간
	private String chgDate;							// 변경일시
	private String chgTime;							// 변경시간
	private String giftPackYn;						// 선물하기여부
	private String giftAddrInpYn;					// 선물배송지등록여부
	private int giftCancelDay;						// 선물하기취소기간
	private String stDate;							// 시작일시
	private String edDate;							// 종료일시
	private String ordDtlStat;						// 주문상세상태코드
	private String goodsCd;							// 상품코드
	private String brandNm;							// 브랜드명
	private String brandGroupNm;					// 브랜드그룹명
	private String shotDelvYn;						// 총알배송여부
	private String goodsNm;							// 상품명
	private int listPrice;							// 정상가(최초판매가)
	private String sysImgNm;						// 이미지파일명
	private int refundAmt;							// 환불금액
	private String exchangeShipCompCd;				// 교환상품 택배사코드
	private String exchangeInvoiceNo;				// 교환상품 송장번호

	// Pagination
	private TscPageRequest pageable;				// 페이징
	private int pageNo = 1;							// 페이지번호
	private int pageSize = 50;						// 페이지목록수
	private int pageUnit = 10;						// 페이지번호수
	
	// 취소 상세
	private String chgDt;							// 취반교 접수 일자
	private int ordAmt;								// 주문금액
	private int ordQty;								// 주문수량
	private int cpn1DcAmt;							// 1차쿠폰할인금액
	private int realOrdAmt;							// 실주문금액
	private int pntDcAmt;							// 포인트사용금액
	private int gfcdUseAmt;							// 상품권사용금액
	private int rfCpn1Amt;							// 환불1차쿠폰할인금액
	private int rfTmtb1Amt;							// 환불다다익선1할인금액
	private int rfTmtb2Amt;							// 환불다다익선2할인금액
	private int rfGoodsCpnAmt;						// 환불상품쿠폰할인금액
	private int rfCartCpnAmt;						// 환불장바구니쿠폰할인금액
	private int rfDelvCpnAmt;						// 환불배송비쿠폰할인금액
	private int rfPntAmt;							// 환불포인트사용금액
	private int rfPrePntAmt;						// 환불선포인트할인금액
	private int rfGfcdUseAmt;						// 환불상품권사용금액
	private int rfDelvGfcdUseAmt;					// 환불배송비상품권사용금액
	private int rfCnclAmt;							// 환불상품취소금액
	private int rfDeliveryFee;						// 환불배송비
	private int rfRealCnclAmt;						// 환불금액(배송비제외)
	private String pgGb;							// PG구분
	private String pgTid;							// PG거래ID
	private String payStat;							// 결제상태
	private String payMeans;						// 결제수단
	private String payMeansNm;						// 결제수단명
	private int priceOrg;							// 원가격
	private int priceSale;							// 할인가격
	private int usePoint;							// 사은품 사용 포인트
	private String supplyCompCd;					// 공급업체코드
	private String supplyCompNm;					// 공급업체명

	// 교환 상세
	private String[] chgItemNmArr;					// 교환상품구성상품명 배열
	private String[] chgColorNmArr;					// 교환상품컬러명 배열
	private String[] chgOptCd1Arr;					// 교환상품옵션1 배열
	private String chgOrdDtlStat;					// 교환상품상세상태
	private String chgColorNm;						// 교환상품컬러명
	private String chgItemNm;						// 교환상품구성상품명
	private String chgOptCd1;						// 교환상품옵션1
	private String cardNm;							// 카드명
	private String cardMips;						// 카드할부
	private String chgRecipNm;						// 교환상품 수령자명
	private String chgRecipEmail;					// 교환상품 수령자이메일
	private String chgRecipZipcode;					// 교환상품 수령자우편번호
	private String chgRecipBaseAddr;				// 교환상품 수령자기본주소
	private String chgRecipDtlAddr;					// 교환상품 수령자상세주소
	private String chgRecipPhnno;					// 교환상품 수령자핸드폰번호
	private String chgRecipTelno;					// 교환상품 수령자전화번호
	private String chgDelvMemo;						// 교환상품 배송메모

	// WMS 예외처리
	private String ordChgGb;						// WMS 예외처리 구분
	private String exceptionQty;					// 미착 예외수량
	
	private String batchYn;							// 배치여부
	
	private String addDeliveryFeeYn;
	private String mallGb;
	private String pgStat;
	private String codFeeYn;
	private String enCloseFeeYn;
	private int addDeliveryFee;	
	private int spanRefundAmt;
	private int spanTotDeliveryFee;
	private int spanTotRtnDelvFee;
	private int codFee;
	private int encloseFee;	
	private int goodsCnt;
	private String npayOrdDtlNo;
	private int orderDtlNo;
	private String ordExchGb;
	private String giftPackCloseDt;
	private int depositAmt;
	private int orgDelvFee;
	private int orgRefundDelvFee;
	private int realDelvAmt;
	private int delvGfcdUseAmt;
	private int rtnRealDelvAmt;
	private int rtnDelvGfcdUseAmt;
	private Integer delvFeeSq;
	private String delvFeeGb;
	private int rowspanRank;
	private int rowspanCnt;

	public String getMaskingOrdNm() {
		return TscSession.getAttribute("maskingYn").equals("Y") ? MaskingUtils.name(getOrdNm()) : getOrdNm();
	}

	public String getMaskingOrderPhnno() {
		return TscSession.getAttribute("maskingYn").equals("Y") ? MaskingUtils.phoneNo(getOrdPhnno()) : getOrdPhnno();
	}

	// 휴대폰 번호 대쉬 붙이기
	public void setHypenRecipPhone() {
		if (StringUtils.isNotBlank(this.recipPhnno) && !this.recipPhnno.contains("-")) {
			if (this.recipPhnno.length() > 10) {
				this.recipPhnno = this.recipPhnno.substring(0, 3) + "-" + this.recipPhnno.substring(3, 7) + "-" + this.recipPhnno.substring(7, 11);
			} else {
				this.recipPhnno = this.recipPhnno.substring(0, 3) + "-" + this.recipPhnno.substring(3, 6) + "-" + this.recipPhnno.substring(6, 10);
			}
		}
	}
}
