package cd.casic.module.execute.docker.dataobject.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;

import java.util.Optional;

/**
 * @description: docker 的断电配置类
 * @author: mianbin
 * @date: 2025/5/26 10:11
 * @version: 1.0
 */
@Data
public class DockerEndpoint {
    private String id;

    private String name;

    private DockerEndpointTypeEnum type;

    private DockerEndpointStateEnum state = DockerEndpointStateEnum.NORMAL;

    private String host;

    private Integer port;

    private String latestTestTime;

    private String createdAt;

    private String updatedAt;

    @Getter
    @AllArgsConstructor
    public enum DockerEndpointTypeEnum {
        LOCAL("本地"),
        REMOTE("远程");
        private final String desc;
    }

    @Getter
    @AllArgsConstructor
    public enum DockerEndpointStateEnum {
        NORMAL("正常"),
        NOT_CONNECT("无法连接"),
        AUTH_FAIL("授权失败");
        private final String desc;
    }

    public String getTypeName() {
        return Optional.ofNullable(this.type).map(DockerEndpointTypeEnum::getDesc).orElse("未知");
    }

    public String getStateName() {
        return Optional.ofNullable(this.state).map(DockerEndpointStateEnum::getDesc).orElse("未知");
    }
}
