package com.eactive.testmaster.server.dto;

import com.eactive.testmaster.common.search.BaseSearch;
import com.eactive.testmaster.common.search.ColumnSearchModel;
import com.eactive.testmaster.common.search.SearchCondition;
import com.eactive.testmaster.common.search.SearchModel;
import com.eactive.testmaster.server.entity.Server;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;

public class ServerSearch implements BaseSearch<Server> {

    private String name;

    private String hostname;

    private String basePath;

    private String port;

    @Override
    public List<SearchModel> buildSearchCondition() {
        List<SearchModel> models = new ArrayList<>();

        if (StringUtils.isNotEmpty(name)) {
            models.add(new ColumnSearchModel("name", SearchCondition.LIKE, name));
        }

        if (StringUtils.isNotEmpty(hostname)) {
            models.add(new ColumnSearchModel("hostname", SearchCondition.LIKE, hostname));
        }

        if (StringUtils.isNotEmpty(basePath)) {
            models.add(new ColumnSearchModel("basePath", SearchCondition.LIKE, basePath));
        }
        if (StringUtils.isNotEmpty(port)) {
            models.add(new ColumnSearchModel("port", SearchCondition.EQUAL, Integer.parseInt(port)));
        }


        return models;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getHostname() {
        return hostname;
    }

    public void setHostname(String hostname) {
        this.hostname = hostname;
    }

    public String getBasePath() {
        return basePath;
    }

    public void setBasePath(String basePath) {
        this.basePath = basePath;
    }

    public String getPort() {
        return port;
    }

    public void setPort(String port) {
        this.port = port;
    }

}
