package com.example.cattletends.entity;

import javax.persistence.*;
import java.time.LocalDateTime;

/**
 * 品种表实体类
 */
@Entity
@Table(name = "cattlebreed", indexes = {
    @Index(name = "idx_breed_name", columnList = "breed_name", unique = true),
    @Index(name = "idx_create_time", columnList = "create_time"),
    @Index(name = "idx_up_time", columnList = "up_time"),
    @Index(name = "idx_is_delet", columnList = "is_delet")
})
public class CattleBreed {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    
    /**
     * 品种名称（唯一）
     */
    @Column(name = "breed_name", nullable = false, unique = true, length = 100)
    private String breedName;
    
    /**
     * 创建时间
     */
    @Column(name = "create_time")
    private LocalDateTime createTime;
    
    /**
     * 更新时间
     */
    @Column(name = "up_time", nullable = false)
    private LocalDateTime upTime;
    
    /**
     * 逻辑删除标志：0=未删除，1=已删除
     */
    @Column(name = "is_delet", nullable = false, columnDefinition = "INT DEFAULT 0")
    private Integer isDelet = 0;
    
    @PrePersist
    protected void onCreate() {
        createTime = LocalDateTime.now();
        upTime = LocalDateTime.now();
        if (isDelet == null) {
            isDelet = 0;
        }
    }
    
    @PreUpdate
    protected void onUpdate() {
        upTime = LocalDateTime.now();
    }
    
    // Getters and Setters
    public Integer getId() {
        return id;
    }
    
    public void setId(Integer id) {
        this.id = id;
    }
    
    public String getBreedName() {
        return breedName;
    }
    
    public void setBreedName(String breedName) {
        this.breedName = breedName;
    }
    
    public LocalDateTime getCreateTime() {
        return createTime;
    }
    
    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }
    
    public LocalDateTime getUpTime() {
        return upTime;
    }
    
    public void setUpTime(LocalDateTime upTime) {
        this.upTime = upTime;
    }
    
    public Integer getIsDelet() {
        return isDelet;
    }
    
    public void setIsDelet(Integer isDelet) {
        this.isDelet = isDelet;
    }
}

