package com.zhongshu.card.client.model.visitor.setting;

import com.google.common.collect.Lists;
import com.zhongshu.card.client.model.base.SuperModel;
import com.zhongshu.card.client.model.form.ComponentFormModel;
import com.zhongshu.card.client.model.org.role.RoleModel;
import com.zhongshu.card.client.model.org.role.RoleSimpleModel;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.apache.commons.lang3.ObjectUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author TRX
 * @date 2025/2/11
 */
@Data
public class VisitorSettingModel extends SuperModel {

    @Schema(description = "组件id")
    private String sceneComponentId;

    @Schema(description = "被访人类型设置")
    private List<RoleSimpleModel> visitorRoles;

    @Schema(description = "角色id")
    private List<String> visitorRoleIds = new ArrayList<>();

    public List<String> getVisitorRoleIds() {
        if (ObjectUtils.isNotEmpty(visitorRoles)) {
            return visitorRoles.stream().map(RoleSimpleModel::getId).collect(Collectors.toList());
        }
        return Lists.newArrayList();
    }

    private String visitorRoleNames = "";

    public String getVisitorRoleNames() {
        if (ObjectUtils.isNotEmpty(visitorRoles)) {
            List<String> visitorRoleNames = visitorRoles.stream().map(RoleSimpleModel::getName).collect(Collectors.toList());
            return String.join(",", visitorRoleNames);
        }
        return "";
    }

    @Schema(description = "访客类型，值从字典来")
    private List<String> visitorTypes;

    @Schema(description = "授权时间")
    private Long minutes;

    @Schema(description = "表单列表")
    private List<ComponentFormModel> fields = new ArrayList<ComponentFormModel>();

}
