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


import io.swagger.annotations.ApiModelProperty;
import lombok.*;

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

import javax.validation.constraints.NotBlank;

import com.oqpo.api.entity.pomng.WishListItemEntity;



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

    @ApiModelProperty(value = "위시리스트번호")
    private String wishListMgntNo;


    @ApiModelProperty(value = "신규 품목리스트")
    private List<SaveWishListItemRequest.SaveWishItemList> gridInsertData;
    @ApiModelProperty(value = "갱신 품목리스트")
    private List<SaveWishListItemRequest.SaveWishItemList> gridUpdateData;
    @ApiModelProperty(value = "삭제 품목리스트")
    private List<SaveWishListItemRequest.SaveWishItemList> gridDeleteData;

    public List<WishListItemEntity> toEntities(List<SaveWishListItemRequest.SaveWishItemList> gridData) {
        List<WishListItemEntity> entities = new ArrayList<>();
        if (gridData == null || gridData.size() == 0)
            return entities;
        gridData.forEach(x -> {
            WishListItemEntity entity = new WishListItemEntity();
            entity.setItemId(x.getItemId());
            entity.setItemNm(x.getItemNm());
            entity.setDelYn(x.getDelYn());
            entities.add(entity);
        });
        return entities;
    }
    

    @Getter
    @Builder
    @AllArgsConstructor(access = AccessLevel.PROTECTED)
    static class SaveWishItemList {
        @NotBlank
        @ApiModelProperty(value = "품목아이디")
        private String itemId; 
        @NotBlank
        @ApiModelProperty(value = "품목명")
        private String itemNm;
        
        @NotBlank
        @ApiModelProperty(value = "삭제여부")
        private String delYn;
    }
}
