package com.willalp.group.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.willalp.common.annotation.Excel;
import com.willalp.common.core.domain.BaseEntity;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

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

/**
 * 群组配置对象 hs_group_config
 *
 * @author willalp
 * @date 2022-07-22
 */

@TableName("hs_group_config")
public class HsGroupConfig extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @TableId
    private String id;

    /**
     * 群组编码
     */
    @Excel(name = "群组编码")
    private String groupCode;

    /**
     * 群组名称
     */
    @Excel(name = "群组名称")
    private String groupName;

    /**
     * 群组成员
     */
    @Excel(name = "群组成员")
    private String groupMember;

    @TableField(exist = false)
    private List<String> groupMemberText = new ArrayList<>();


    /**
     * 是否删除（0.未删除；1.已删除）
     */
    @Excel(name = "是否删除", readConverterExp = "0=.未删除；1.已删除")
    @TableLogic
    private Integer isDelete;

    public void setId(String id) {
        this.id = id;
    }

    public String getId() {
        return id;
    }

    public void setGroupCode(String groupCode) {
        this.groupCode = groupCode;
    }

    public String getGroupCode() {
        return groupCode;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    public String getGroupName() {
        return groupName;
    }

    public void setGroupMember(String groupMember) {
        this.groupMember = groupMember;
    }

    public void setGroupMemberOne(String groupMember) {
        String[] member = getGroupMembers();
        String[] newMember = new String[member.length + 1];
        for (int i = 0; i < member.length; i++) {
            newMember[i] = member[i];
        }
        newMember[newMember.length - 1] = groupMember;
        this.groupMember = groupMember;
    }

    public String getGroupMember() {
        return this.groupMember;
    }

    public String[] getGroupMembers() {
        if (StringUtils.isNotBlank(this.groupMember)) {
            return this.groupMember.split(",");
        }
        return null;
    }


    public void setIsDelete(Integer isDelete) {
        this.isDelete = isDelete;
    }

    public Integer getIsDelete() {
        return isDelete;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("id", getId())
                .append("groupCode", getGroupCode())
                .append("groupName", getGroupName())
                .append("groupMember", getGroupMember())
                .append("isDelete", getIsDelete())
                .append("createBy", getCreateBy())
                .append("createTime", getCreateTime())
                .append("updateBy", getUpdateBy())
                .append("updateTime", getUpdateTime())
                .append("remark", getRemark())
                .toString();
    }

    public List<String> getGroupMemberText() {
        return groupMemberText;
    }

    public void setGroupMemberText(List<String> groupMemberText) {
        this.groupMemberText = groupMemberText;
    }
}
