package com.ecep.contract.model;

import java.util.Objects;

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

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;

/**
 * 用友U8系统中的合同分组
 */
@Getter
@Setter
@Entity
@Table(name = "CONTRACT_GROUP", schema = "supplier_ms")
public class ContractGroup implements IdentityEntity, NamedEntity, Voable<ContractGroupVo> {
    @Id
    @Column(name = "ID", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    /**
     * 用友U8系统中的合同分组代码
     */
    @Column(name = "CODE")
    private String code;

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

    @Column(name = "TITLE")
    private String title;


    public static String toString(ContractGroup group) {
        if (group != null) {
            return group.getCode() + " " + group.getName();
        } else {
            return "-";
        }
    }

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

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

    @Override
    public ContractGroupVo toVo() {
        ContractGroupVo vo = new ContractGroupVo();
        vo.setId(id);
        vo.setName(name);
        vo.setCode(code);
        vo.setTitle(title);
        // 注意：ContractGroup实体类中似乎没有parentId、order、description和active字段，但ContractGroupVo中有这些字段
        // 由于实体类中没有这些字段，所以无法设置它们的值
        return vo;
    }
}
