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

import cn.reghao.file.api.dto.ImageMeta;
import cn.reghao.jutil.jdk.web.db.BaseObject;
import lombok.Getter;
import lombok.NoArgsConstructor;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

/**
 * @author reghao
 * @date 2024-10-31 13:57:28
 */
@NoArgsConstructor
@Getter
public class PostItem extends BaseObject<Integer> {
    @NotNull
    private Long albumId;
    @NotBlank
    private String postId;
    @NotNull
    private Integer pos;
    @NotNull
    private Integer channelCode;
    @NotNull
    private String objectId;
    @NotNull
    private String format;
    @NotNull
    private String url;
    @NotNull
    private Integer width;
    @NotNull
    private Integer height;
    @NotNull
    private Boolean horizontal;

    public PostItem(long albumId, String postId) {
        this.albumId = albumId;
        this.postId = postId;
        this.pos = 1;
        this.channelCode = 0;
        this.objectId = "";
        this.format = "";
        this.url = "";
        this.width = 0;
        this.height = 0;
        this.horizontal = false;
    }

    public PostItem(long albumId, int channelCode, ImageMeta imageMeta) {
        this.albumId = albumId;
        this.postId = "";
        this.pos = 1;
        this.channelCode = channelCode;
        this.objectId = imageMeta.getObjectId();
        this.format = imageMeta.getFormat();
        this.url = imageMeta.getUrl();
        this.width = imageMeta.getWidth();
        this.height = imageMeta.getHeight();
        this.horizontal = imageMeta.getWidth() > imageMeta.getHeight();
    }
}
