package com.purui.prims.common.pojo;

import com.google.common.base.Objects;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;

@Data
public class Order {

    @ApiModelProperty(value = "排序字段")
    @NotBlank(message = "Invalid order column")
    private String column;

    @ApiModelProperty(value = "排序方向")
    private String direction = Constants.ASC_UPPER;

    public Order(String column, String direction) {
        this.column = column;
        this.direction = direction;
    }

    public Order() {
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("{");
        sb.append("\"column\":\"")
                .append(column).append('\"');
        sb.append(",\"direction\":\"")
                .append(direction).append('\"');
        sb.append('}');
        return sb.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Order order = (Order) o;
        return Objects.equal(column, order.column) && Objects.equal(direction,
                order.direction);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(column, direction);
    }
}
