package com.test.musichouduan.entity;

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

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

/**
 * 歌单实体类
 */
@Data
@Entity
@Table(name = "playlist")
public class Playlist {

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

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

    /**
     * 封面URL
     */
    @Column(length = 255)
    private String cover;

    /**
     * 歌单描述
     */
    @Column(length = 500)
    private String description;

    /**
     * 创建者
     */
    @ManyToOne
    @JoinColumn(name = "creator_id")
    private User creator;

    /**
     * 歌单类型
     */
    @ManyToOne
    @JoinColumn(name = "type_id")
    private PlaylistType type;

    /**
     * 是否官方歌单：0-否，1-是
     */
    @Column
    private Integer isOfficial = 0;

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

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

    /**
     * 播放次数
     */
    @Column
    private Long playCount = 0L;

    /**
     * 歌单中的音乐
     */
    @ManyToMany
    @JoinTable(
        name = "playlist_music",
        joinColumns = @JoinColumn(name = "playlist_id"),
        inverseJoinColumns = @JoinColumn(name = "music_id")
    )
    private Set<Music> musics = new HashSet<>();

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

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

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