package com.ecep.contract.model;

import java.time.LocalDateTime;
import java.util.Objects;

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

import jakarta.persistence.Column;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@jakarta.persistence.Entity
@Table(name = "EMPLOYEE_AUTH_BIND", schema = "supplier_ms")
public class EmployeeAuthBind implements BasedEntity, IdentityEntity, Voable<EmployeeAuthBindVo> {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID", nullable = false)
    private Integer id;

    @JoinColumn(name = "EMPLOYEE_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private Employee employee;

    @Column(name = "IP")
    private String ip;

    @Column(name = "MAC")
    private String mac;

    /**
     * 创建时间
     */
    @Column(name = "CREATE_TIME")
    private LocalDateTime createTime;
    /**
     * 更新人
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "UPDATE_BY")
    @ToString.Exclude
    private Employee updater;

    @Column(name = "UPDATE_TIME")
    private LocalDateTime updateTime;

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

    @Override
    public String toPrettyString() {
        return ip + " " + mac;
    }

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

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

    @Override
    public EmployeeAuthBindVo toVo() {
        EmployeeAuthBindVo vo = new EmployeeAuthBindVo();
        vo.setId(id);
        vo.setEmployeeId(employee != null ? employee.getId() : null);
        vo.setIp(ip);
        vo.setMac(mac);
        vo.setCreateTime(createTime);
        vo.setUpdaterId(updater != null ? updater.getId() : null);
        vo.setUpdateTime(updateTime);
        vo.setDescription(description);
        return vo;
    }
}
