package com.eactive.httpmockserver.server.dto;

import com.eactive.httpmockserver.common.search.BaseSearch;
import com.eactive.httpmockserver.common.search.ColumnSearchModel;
import com.eactive.httpmockserver.common.search.SearchCondition;
import com.eactive.httpmockserver.common.search.SearchModel;
import com.eactive.httpmockserver.server.entity.Server;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

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;
    }

}
