package com.lesingle.modules.device.vo;

import com.lesingle.modules.ugc.entity.UgcWork;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 终端设备作品列表项
 */
@Data
@Schema(description = "终端设备作品列表项")
public class DeviceWorkItemVo implements Serializable {

    @Schema(description = "作品ID")
    private Long id;

    @Schema(description = "作品标题")
    private String title;

    @Schema(description = "封面图URL")
    private String coverUrl;

    @Schema(description = "作品描述")
    private String description;

    @Schema(description = "发布状态: draft/unpublished/pending_review/published/rejected")
    private String status;

    @Schema(description = "作者名称")
    private String authorName;

    @Schema(description = "乐读派创作进度: -1=FAILED, 0=INIT, 1=PENDING, 2=PROCESSING, 3=COMPLETED, 4=CATALOGED, 5=DUBBED")
    private Integer leaiStatus;

    @Schema(description = "页数")
    private Integer pageCount;

    @Schema(description = "创建时间")
    private LocalDateTime createTime;

    @Schema(description = "修改时间")
    private LocalDateTime modifyTime;

    /**
     * 从 UgcWork 实体转换
     */
    public static DeviceWorkItemVo fromEntity(UgcWork work) {
        DeviceWorkItemVo vo = new DeviceWorkItemVo();
        vo.setId(work.getId());
        vo.setTitle(work.getTitle());
        vo.setCoverUrl(work.getCoverUrl());
        vo.setDescription(work.getDescription());
        vo.setStatus(work.getStatus());
        vo.setAuthorName(work.getAuthorName());
        vo.setLeaiStatus(work.getLeaiStatus());
        vo.setCreateTime(work.getCreateTime());
        vo.setModifyTime(work.getModifyTime());
        // pageCount 从 _count.pages 获取
        if (work.getCount() != null) {
            vo.setPageCount(work.getCount().getPages());
        }
        return vo;
    }
}
