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

import com.oqpo.api.entity.oper.NticeTargetEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

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

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

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

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

    @ApiModelProperty(value = "공지번호")
    private String nticeNo;

    @NotBlank
    @ApiModelProperty(value = "타겟구분")
    private String targetCd;

    @NotBlank
    @ApiModelProperty(value = "공지제목")
    private String nticeTitl;

    @NotBlank
    @ApiModelProperty(value = "공지내용")
    private String nticeDesc;

    @ApiModelProperty(value = "삭제여부")
    private String delYn;

    @NotBlank
    @ApiModelProperty(value = "게시시작일")
    private String notiStDay;

    @NotBlank
    @ApiModelProperty(value = "게시종료일")
    private String notiEdDay;

    @ApiModelProperty(value = "파일번호")
    private String fileNo;

    @ApiModelProperty(value = "브랜드대상여부")
    private String brandChk;

    @ApiModelProperty(value = "매장대상여부")
    private String shopChk;

    @ApiModelProperty(value = "공급사대상여부")
    private String supplyChk;


    @ApiModelProperty(value = "등록상세리스트")
    private List<SaveNticeTarget> gridInsertData;

    @ApiModelProperty(value = "수정상세리스트")
    private List<SaveNticeTarget> gridUpdateData;

    @ApiModelProperty(value = "삭제상세리스트")
    private List<SaveNticeTarget> gridDeleteData;

    public List<NticeTargetEntity> toNticeTargetEntities(List<SaveNticeTarget> gridData) {
        List<NticeTargetEntity> entities = new ArrayList<>();
        gridData.forEach(x -> {
            NticeTargetEntity entity = new NticeTargetEntity();
            entity.setBrandId(x.getBrandId());
            entity.setNticeNo(x.getNticeNo());
            entities.add(entity);
        });
        return entities;
    }

    @Getter
    @Builder
    @AllArgsConstructor(access = AccessLevel.PROTECTED)
    static class SaveNticeTarget {
        @NotBlank
        @ApiModelProperty(value = "브랜드아이디")
        private String brandId;

        @ApiModelProperty(value = "공지번호")
        private String nticeNo;
    }
}
