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.HashSet;
import java.util.Set;

/**
 * 音乐实体类
 */
@Data
@Entity
@Table(name = "music")
public class Music {

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

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

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

    /**
     * 音乐文件URL
     */
    @Column(nullable = false, length = 255)
    private String url;

    /**
     * 歌词
     */
    @Column(columnDefinition = "TEXT")
    private String lyric;

    /**
     * 时长(秒)
     */
    @Column
    private Integer duration;

    /**
     * 专辑
     */
    @Column(length = 100)
    private String album;

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

    /**
     * 点赞数
     */
    @Column
    private Integer likeCount;

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

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

    /**
     * 热度分数
     */
    @Column
    private Double hotScore;

    /**
     * 歌手列表
     */
    @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinTable(
        name = "music_singer",
        joinColumns = @JoinColumn(name = "music_id"),
        inverseJoinColumns = @JoinColumn(name = "singer_id")
    )
    private Set<Singer> singers = new HashSet<>();

    /**
     * 音乐类型列表
     */
    @ManyToMany
    @JoinTable(
        name = "music_type_relation",
        joinColumns = @JoinColumn(name = "music_id"),
        inverseJoinColumns = @JoinColumn(name = "type_id")
    )
    private Set<MusicType> types = new HashSet<>();

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

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