package com.muyu.web.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.web.domain.model.ServerConfigModel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.function.Supplier;

/**
 * 服务器配置类
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName(value = "server_config")
public class ServerConfig {

    /**
     * 主键
     */
    @TableId(value = "id",type = IdType.AUTO)
    private Long id;


    /**
     * 主机地址
     */
    private String host;

    /**
     * 端口号
     */
    private String port;

    /**
     * 负载地址
     */
    private String url;

    /**
     * 默认MOTT地址
     */
    private String defaultMqttAddr;

    /**
     * 默认MQTT主题
     */
    private String defaultMqttTopic;

    /**
     * 默认MOTT交付级别
     */
    private Integer defaultMqttQos;


    public static  ServerConfig modeBuild(ServerConfigModel serverConfigModel, Supplier<Long> idKey){
        return builder()
                .id(idKey.get())
                .host(serverConfigModel.getHost())
                .port(serverConfigModel.getPort())
                .url(serverConfigModel.getUrl())
                .defaultMqttAddr(serverConfigModel.getDefaultMqttAddr())
                .defaultMqttTopic(serverConfigModel.getDefaultMqttTopic())
                .defaultMqttQos(serverConfigModel.getDefaultMqttQos())
                .build();



    }
}
