package com.oqpo.api.web.dto.request.stinfo.spply;

import com.oqpo.api.entity.oper.AfflSaleInfoEntity;
import com.oqpo.api.entity.stinfo.SpplyMgrEntity;
import com.oqpo.api.web.dto.request.oper.affl.SaveAfflRequest;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

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

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

    @ApiModelProperty(value = "공급사아이디")
    private String spplyId;

    @NotBlank
    @ApiModelProperty(value = "공급사명")
    private String spplyNm;

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

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

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

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

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

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

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

    @ApiModelProperty(value = "기업구분코드")
    private String corpDvsn;

    @ApiModelProperty(value = "담당자명")
    private String mgrNm;

    @ApiModelProperty(value = "지역코드")
    private String areaCd;

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

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

    @ApiModelProperty(value = "담당자핸드폰번호")
    private String mgrMblNo;

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

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

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

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

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

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

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

    @ApiModelProperty(value = "통장사본파일번호")
    private String bbookCopyFileNo;

    @ApiModelProperty(value = "사업자등록증파일번호")
    private String bsnsRegFileNo;

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

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

    @ApiModelProperty(value = "공급사담당자리스트")
    private List<SaveSpplyMgr> gridInsertData;

    @ApiModelProperty(value = "공급사담당자리스트")
    private List<SaveSpplyMgr> gridUpdateData;

    @ApiModelProperty(value = "공급사담당자리스트")
    private List<SaveSpplyMgr> gridDeleteData;

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

        gridData.forEach(x -> {
            SpplyMgrEntity entity = new SpplyMgrEntity();
            entity.setSpplyId(x.getSpplyId());
            entity.setSpplyMgrId(x.getSpplyMgrId());
            entity.setSpplyMgrNm(x.getSpplyMgrNm());
            entity.setRprstTelNo(x.getRprstTelNo());
            entity.setRprstEmal(x.getRprstEmal());
            entity.setPosition(x.getPosition());
            entity.setAssgnTask(x.getAssgnTask());
            entities.add(entity);
        });
        return entities;
    }

    @Getter
    @Builder
    @AllArgsConstructor(access = AccessLevel.PROTECTED)
    static class SaveSpplyMgr {
        @ApiModelProperty(value = "공급사아이디")
        private String spplyId;

        @ApiModelProperty(value = "영업담당자순번")
        private Integer spplyMgrId;

        @ApiModelProperty(value = "담당자명")
        private String spplyMgrNm;

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

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

        @ApiModelProperty(value = "직위")
        private String position;

        @ApiModelProperty(value = "담당업무코드")
        private String assgnTask;
    }
}
