/**
 * Multimud Helper.
 * 
 * Copyright (C) 2009 Benjamin Lerman<br>
 * Copyright (C) 2009 Jacques ???
 * 
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package net.ambre.multimud_helper.bean;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Formatter;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

/**
 * a skill that a trainer has. It has the skill itself, as well as the ramge of level the trainer can teach.
 */
@Entity
public class TrainedSkill implements Serializable, Comparable<TrainedSkill> {

    /**
     * {@inheritedDoc}
     */
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        Formatter formatter = new Formatter(sb);
        formatter.format("%20s from %15s to %15s", skill.getName(), "(" + minLevel + ")", "(" + maxLevel + ")");
        return sb.toString();
    }

    /**
     * serial version uid for {@link java.io.Serializable}.
     */
    private static final long serialVersionUID = 1L;

    /**
     * the primary key of the object.
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    /**
     * the skill being trained.
     */
    @ManyToOne
    private Skill skill;

    /**
     * the minimum level to have for this skill to be trained.
     */
    @Enumerated(EnumType.STRING)
    private SkillLevel minLevel;

    /**
     * the maximum level to have for this skill to be trained.
     */
    @Enumerated(EnumType.STRING)
    private SkillLevel maxLevel;

    /**
     * getter for the id property.
     * 
     * @return the id
     */
    public Integer getId() {
        return this.id;
    }

    /**
     * setter for the id property.
     * 
     * @param id the id to set
     */
    public void setId(Integer id) {
        this.id = id;
    }

    /**
     * getter for the skill property.
     * 
     * @return the skill
     */
    public Skill getSkill() {
        return this.skill;
    }

    /**
     * setter for the skill property.
     * 
     * @param skill the skill to set
     */
    public void setSkill(Skill skill) {
        this.skill = skill;
    }

    /**
     * getter for the minLevel property.
     * 
     * @return the minLevel
     */
    public SkillLevel getMinLevel() {
        return this.minLevel;
    }

    /**
     * setter for the minLevel property.
     * 
     * @param minLevel the minLevel to set
     */
    public void setMinLevel(SkillLevel minLevel) {
        this.minLevel = minLevel;
    }

    /**
     * getter for the maxLevel property.
     * 
     * @return the maxLevel
     */
    public SkillLevel getMaxLevel() {
        return this.maxLevel;
    }

    /**
     * setter for the maxLevel property.
     * 
     * @param maxLevel the maxLevel to set
     */
    public void setMaxLevel(SkillLevel maxLevel) {
        this.maxLevel = maxLevel;
    }

    /**
     * {@inheritedDoc}
     */
    @Override
    public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this, Arrays.asList("id"));
    }

    /**
     * {@inheritedDoc}
     */
    @Override
    public boolean equals(Object obj) {
        return EqualsBuilder.reflectionEquals(this, obj, Arrays.asList("id"));
    }

    /**
     * {@inheritedDoc}
     */
    public int compareTo(TrainedSkill other) {
        return CompareToBuilder.reflectionCompare(this, other, Arrays.asList("id"));
    }

}
