package com.ecep.contract.model;

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

import com.ecep.contract.util.HibernateProxyUtils;
import com.ecep.contract.vo.ProductTypeVo;

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

/**
 * 产品类型
 */
@Getter
@Setter
@Entity
@Table(name = "PRODUCT_TYPE")
public class ProductType implements BasedEntity, IdentityEntity, Serializable, Voable<ProductTypeVo> {
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "ID", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

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

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

    @Column(name = "DESCRIPTION", columnDefinition = "TEXT")
    private String description;

    @Override
    public String toPrettyString() {
        return code + " " + name;
    }

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

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

    @Override
    public ProductTypeVo toVo() {
        ProductTypeVo vo = new ProductTypeVo();
        vo.setId(getId());
        vo.setName(getName());
        vo.setCode(getCode());
        vo.setDescription(getDescription());
        // parentId和order字段在ProductType中不存在，设置为null
        vo.setParentId(null);
        vo.setOrder(null);
        // active字段设置为默认值false
        vo.setActive(false);
        return vo;
    }
}