/**
 * Copyright (c) 2015 Bosch Software Innovations GmbH and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.eclipse.hawkbit.ui.common.entity;

import java.io.Serializable;

import org.eclipse.hawkbit.repository.model.SoftwareModule;

/**
 * To hold software module name and Id.
 *
 */
public class SoftwareModuleIdName implements Serializable {

    private static final long serialVersionUID = -6317413180936148514L;

    private final Long id;
    private final String name;
    private final String version;

    /**
     * @param id
     *            of the {@link SoftwareModule#getId()}
     * @param name
     *            of the {@link SoftwareModule#getName()}
     * @param version
     *            the {@link SoftwareModule#getVersion()}
     */
    public SoftwareModuleIdName(final Long id, final String name, final String version) {
        this.id = id;
        this.name = name;
        this.version = version;
    }

    /**
     * Constructor.
     * 
     * @param softwareModule
     *            the softwareModule
     */
    public SoftwareModuleIdName(final SoftwareModule softwareModule) {
        this(softwareModule.getId(), softwareModule.getName(), softwareModule.getVersion());
    }

    public Long getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getVersion() {
        return version;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (id == null ? 0 : id.hashCode());
        return result;
    }

    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final SoftwareModuleIdName other = (SoftwareModuleIdName) obj;
        if (id == null) {
            if (other.id != null) {
                return false;
            }
        } else if (!id.equals(other.id)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        // only return the ID because it's used in vaadin for setting the item
        // id in the dom
        return id.toString();
    }
}
