package com.sckw.core.model.base;

import com.sckw.core.utils.StringUtils;

import java.util.List;

/**
 * ids处理接口类
 *
 * @author xucaiqin
 * @date 2023-07-27 16:40:15
 */
public interface IdsList {
    default String getId() {
        return "";
    }

    default String getIds() {
        return "";
    }

    /**
     * 返回long类型的id
     *
     * @return Long
     */
    default Long getIdLong() {
        String s;
        if (StringUtils.isNotBlank(s = getId())) {
            try {
                return Long.parseLong(s);
            } catch (NumberFormatException e) {
                return null;
            }
        }
        return null;
    }

    default Long changeId(String id) {
        if (StringUtils.isNotBlank(id)) {
            try {
                return Long.parseLong(id);
            } catch (NumberFormatException e) {
                return null;
            }
        }
        return null;
    }

    default List<Long> getIdList() {
        return StringUtils.splitStrToList(getIds(), Long.class);
    }

    default List<String> getIdsList() {
        return StringUtils.splitStrToList(getIds(), String.class);
    }
}
