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

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

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

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

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

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

    @NotBlank
    @ApiModelProperty(value = "사용자id")
    private String userId;

    @NotBlank
    @ApiModelProperty(value = "사용자명")
    private String userNm;

    @NotBlank
    @ApiModelProperty(value = "핸드폰번호")
    private String telNo;

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

    @ApiModelProperty(value = "패스워드")
    private String userPw;

    @NotBlank
    @ApiModelProperty(value = "사용자상태코드")
    private String userStatCd;

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

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

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

    public List<UserAuthInfoEntity> toUserAuthEntities(List<SaveUserAuthDtl> gridData) {
        List<UserAuthInfoEntity> entities = new ArrayList<>();
        gridData.forEach(x -> {
            UserAuthInfoEntity entity = new UserAuthInfoEntity();
            entity.setUserId(x.getUserId());
            entity.setAuthNo(x.getAuthNo());
            entities.add(entity);
        });
        return entities;
    }

    @Getter
    @Builder
    @AllArgsConstructor(access = AccessLevel.PROTECTED)
    static class SaveUserAuthDtl {
        @NotBlank
        @ApiModelProperty(value = "사용자 ID")
        private String userId;

        @NotBlank
        @ApiModelProperty(value = "권한번호")
        private String authNo;
    }
}
