package com.ecep.contract.model;

import java.io.Serializable;
import java.util.Objects;

import com.ecep.contract.UnitType;
import com.ecep.contract.util.HibernateProxyUtils;

import jakarta.persistence.Column;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;

/**
 * 单位
 */
@Getter
@Setter
@jakarta.persistence.Entity
@Table(name = "UNIT", schema = "supplier_ms")
public class Unit implements IdentityEntity, NamedEntity, Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID", nullable = false)
    private Integer id;

    @Column(name = "CODE")
    private String code;

    @Column(name = "NAME")
    private String name;

    @Enumerated(EnumType.ORDINAL)
    @Column(name = "UNIT_TYPE")
    private UnitType unitType;

    // 转换比例，与标准单位之间的比例
    @Column(name = "RATIO")
    private double ratio;

    @Column(name = "STANDARD")
    private boolean standard;

    @Override
    public final boolean equals(Object object) {
        if (this == object) {
            return true;
        }
        if (object == null) {
            return false;
        }
        if (HibernateProxyUtils.isNotEffectiveClassEquals(object, this)) {
            return false;
        }
        Unit that = (Unit) object;
        return getId() != null && Objects.equals(getId(), that.getId());
    }

    @Override
    public final int hashCode() {
        return HibernateProxyUtils.hashCode(this);
    }
}
