package com.cool.store.entity;

import com.cool.store.enums.DataSourceEnum;
import com.google.common.collect.Lists;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;

/**
 * 
 * @author   zhangchenbiao
 * @date   2023-06-08 10:54
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class EnterpriseUserRoleDO implements Serializable {
    @ApiModelProperty("主键id")
    private Integer id;

    @ApiModelProperty("角色id")
    private String roleId;

    @ApiModelProperty("用户id")
    private String userId;

    @ApiModelProperty("type")
    private Integer type;

    @ApiModelProperty("删除标识")
    private Boolean deleted;

    @ApiModelProperty("创建时间")
    private Date createTime;

    @ApiModelProperty("更新时间")
    private Date updateTime;

    public static List<EnterpriseUserRoleDO> convertSyncDO(String roleId, List<String> userIds){
        if(CollectionUtils.isEmpty(userIds)){
            return Lists.newArrayList();
        }
        List<EnterpriseUserRoleDO> resultList = new ArrayList<>();
        for (String userId : userIds) {
            EnterpriseUserRoleDO userRole = new EnterpriseUserRoleDO();
            userRole.setRoleId(roleId);
            userRole.setUserId(userId);
            userRole.setType(DataSourceEnum.SYNC.getCode());
            userRole.setDeleted(Boolean.FALSE);
            userRole.setCreateTime(new Date());
            userRole.setUpdateTime(new Date());
            resultList.add(userRole);
        }
        return resultList;
    }
}