package jnpf.model.cultivate.vo.teaching;

import com.fasterxml.jackson.annotation.JsonFormat;
import jnpf.util.DateUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.util.Date;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class RecordPageListVo {
    /**
     * id
     */
    private String id;
    /**
     * 门店名称
     */
    private String storeName;

    /**
     * 学员名称
     */
    private String userName;

    /**
     * 岗位名称
     */
    private String postName;

    /**
     * 技能点名称
     */
    private String skillName;

    /**
     * 练习视频地址
     */
    private String videoPath;

    /**
     * 练习视频封面
     */
    private String videoCover;

    /**
     * 视频类型(1-竖屏播放, 2-横屏播放)
     */
    private Integer videoActionType;

    /**
     * 练习时长(秒)
     */
    private BigDecimal videoDuration;

    /**
     * 练习日期（yyyy-MM-dd）
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    private Date date;

    public static RecordExportListVo convert(RecordPageListVo listVo) {
        return RecordExportListVo.builder()
            .storeName(listVo.getStoreName())
            .userName(listVo.getUserName())
            .postName(listVo.getPostName())
            .skillName(listVo.getSkillName())
            //.videoPath(listVo.getVideoPath())
            //.videoDuration(formatSeconds(listVo.getVideoDuration()))
            .date(DateUtil.daFormat(listVo.getDate()))
            .build();
    }
    public static String formatSeconds(BigDecimal totalSeconds) {
        if (totalSeconds.compareTo(BigDecimal.ZERO) < 0) {
            throw new IllegalArgumentException("输入秒数不能为负数");
        }
        // 定义时间单位常量
        final BigDecimal SECONDS_PER_DAY = new BigDecimal(86400);
        final BigDecimal SECONDS_PER_HOUR = new BigDecimal(3600);
        final BigDecimal SECONDS_PER_MINUTE = new BigDecimal(60);
        // 计算各时间单位
        BigDecimal[] dayParts = totalSeconds.divideAndRemainder(SECONDS_PER_DAY);
        long days = dayParts[0].longValue();
        BigDecimal remaining = dayParts[1];
        BigDecimal[] hourParts = remaining.divideAndRemainder(SECONDS_PER_HOUR);
        long hours = hourParts[0].longValue();
        remaining = hourParts[1];
        BigDecimal[] minuteParts = remaining.divideAndRemainder(SECONDS_PER_MINUTE);
        long minutes = minuteParts[0].longValue();
        BigDecimal seconds = minuteParts[1];
        // 构建结果字符串
        StringBuilder result = new StringBuilder();
        if (days > 0) {
            result.append(days).append("天");
        }
        if (hours > 0) {
            result.append(hours).append("小时");
        }
        if (minutes > 0) {
            result.append(minutes).append("分");
        }
        // 处理秒部分：若秒>0 或 结果为空时添加
        if (seconds.compareTo(BigDecimal.ZERO) > 0 || result.length() == 0) {
            // 移除末尾多余的零（如 5.0 -> "5"，5.50 -> "5.5"）
            String formattedSeconds = seconds.stripTrailingZeros().toPlainString();
            result.append(formattedSeconds).append("秒");
        }
        return result.toString();
    }
}