package com.oqpo.api.web.dto.request.act;

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

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

@Getter
@Setter
public class SaveActionRequest {
    @ApiModelProperty(value = "메뉴번호")
    private Integer menuNo;

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

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

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

    public List<ActionEntity> toCodeEntities(List<SaveActionInfo> gridData) {
        List<ActionEntity> entities = new ArrayList<>();
        gridData.forEach(x -> {
            ActionEntity entity = new ActionEntity();
            entity.setMenuNo(x.getMenuNo());
            entity.setActId(x.getActId());
            entity.setActTpCd(x.getActTpCd());
            entity.setActNm(x.getActNm());
            entity.setUseYn(x.getUseYn());
            entity.setConnUrl(x.getConnUrl());
            entity.setWriteYn(x.getWriteYn());
            entities.add(entity);
        });
        return entities;
    }

    @Getter
    @Builder
    @AllArgsConstructor(access = AccessLevel.PROTECTED)
    static class SaveActionInfo {
        @ApiModelProperty(value = "CRUD")
        private String viewCd;

        @ApiModelProperty(value = "메뉴번호")
        private Integer menuNo;

        @ApiModelProperty(value = "액션Id")
        private String actId;

        @ApiModelProperty(value = "액션타입")
        private String actTpCd;

        @ApiModelProperty(value = "액션명")
        private String actNm;

        @ApiModelProperty(value = "사용여부")
        private String useYn;

        @ApiModelProperty(value = "접속url")
        private String connUrl;

        @ApiModelProperty(value = "쓰기여부")
        private String writeYn;
    }
}
