package com.oqpo.api.web.dto.request.oper.affl;

import com.oqpo.api.entity.CodeEntity;
import com.oqpo.api.entity.oper.AfflEntity;
import com.oqpo.api.entity.oper.AfflSaleInfoEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.validation.constraints.NotBlank;
import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
public class SaveAfflRequest {
    @NotBlank
    @ApiModelProperty(value = "CRUD")
    private String viewCd;

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

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

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

    @ApiModelProperty(value = "약어")
    private String afflAbbr ;

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

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

    @ApiModelProperty(value = "업태")
    private String bsnsCndt ;

    @ApiModelProperty(value = "업종")
    private String ctgrBsns ;

    @ApiModelProperty(value = "대표자명")
    private String ownerNm ;

    @ApiModelProperty(value = "대표자연락처")
    private String ownerTelNo ;

    @ApiModelProperty(value = "대표팩스번호")
    private String rprstFaxNo ;

    @ApiModelProperty(value = "대표이메일")
    private String rprstEmai ;

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

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

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

    @ApiModelProperty(value = "대표전화번호")
    private String rprstTelNo ;

    @ApiModelProperty(value = "x좌표")
    private String latX ;

    @ApiModelProperty(value = "Y좌표")
    private String longY ;

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

    @NotBlank
    @ApiModelProperty(value = "사용 시작일")
    private String joinSttDt ;

    @ApiModelProperty(value = "사용 종료일")
    private String joinEndDt ;

    @ApiModelProperty(value = "로고 이미지파일번호")
    private String cmpnyLogoFileNo ;

    @ApiModelProperty(value = "기업형태")
    private String corpType ;

    @ApiModelProperty(value = "등록영업담당자리스트")
    private List<SaveAfflSale> gridInsertData;

    @ApiModelProperty(value = "수정영업담당자리스트")
    private List<SaveAfflSale> gridUpdateData;

    @ApiModelProperty(value = "삭제영업담당자리스트")
    private List<SaveAfflSale> gridDeleteData;

    public List<AfflSaleInfoEntity> toCodeEntities(List<SaveAfflSale> gridData) {
        List<AfflSaleInfoEntity> entities = new ArrayList<>();
        if (gridData == null || gridData.size() == 0)
            return entities;

        gridData.forEach(x -> {
            AfflSaleInfoEntity entity = new AfflSaleInfoEntity();
            entity.setAfflShopId(x.getAfflShopId());
            entity.setSaleMgrId(x.getSaleMgrId());
            entities.add(entity);
        });
        return entities;
    }

    @Getter
    @Builder
    @AllArgsConstructor(access = AccessLevel.PROTECTED)
    static class SaveAfflSale {
        @ApiModelProperty(value = "가맹점아이디")
        private String afflShopId;

        @NotBlank
        @ApiModelProperty(value = "영업담당자아이디")
        private String saleMgrId;

    }
}
