package cn.reghao.tnb.content.app.data.model.po;

import cn.reghao.jutil.jdk.web.db.BaseObject;
import cn.reghao.tnb.content.api.constant.PostScope;
import cn.reghao.tnb.common.auth.UserContext;
import cn.reghao.tnb.content.app.data.model.dto.AudioPublishSbt;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * @author reghao
 * @date 2023-01-29 10:07:12
 */
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Data
public class AudioPost extends BaseObject<Integer> {
    private String audioId;
    private String audioFileId;
    private Integer channelCode;
    private String audioUrl;
    private String title;
    private int duration;
    private String codec;
    private int scope;
    private LocalDateTime publishAt;
    private Long publishBy;

    public AudioPost(String audioId, String audioUrl, int duration, String codec, AudioPublishSbt audioPublishSbt) {
        this.audioId = audioId;
        this.audioFileId = audioPublishSbt.getAudioFileId();
        this.audioUrl = audioUrl;
        this.title = audioPublishSbt.getTitle();
        this.duration = duration;
        this.codec = codec;
        this.scope = PostScope.PUBLIC.getCode();
        this.publishAt = audioPublishSbt.getScheduledPubDate() != null ? audioPublishSbt.getScheduledPubDate() : LocalDateTime.now();
        this.publishBy = UserContext.getUserId();
    }
}
