package com.test.musichouduan.entity;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;
import java.util.Set;
import java.util.HashSet;

/**
 * 歌手实体类
 */
@Data
@Entity
@Table(name = "singer")
@EqualsAndHashCode(exclude = {"musics"})
public class Singer {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 歌手名称
     */
    @Column(nullable = false, length = 100)
    private String name;

    /**
     * 歌手头像URL
     */
    @Column(length = 255)
    private String avatar;

    /**
     * 歌手简介
     */
    @Column(columnDefinition = "TEXT")
    private String introduction;

    /**
     * 歌手类型ID
     */
    @ManyToOne
    @JoinColumn(name = "type_id")
    private SingerType type;

    /**
     * 收藏数
     */
    @Column
    private Integer collectCount;

    /**
     * 评论数
     */
    @Column
    private Integer commentCount;

    /**
     * 创建时间
     */
    @CreationTimestamp
    @Column(nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @UpdateTimestamp
    @Column(nullable = false)
    private LocalDateTime updateTime;

    /**
     * 歌手关联的音乐
     */
    @ManyToMany(mappedBy = "singers")
    private Set<Music> musics = new HashSet<>();

    /**
     * 热度分，不持久化到数据库
     */
    @Transient
    private double hotScore;
}
