package com.ycwl.basic.model.mobile.video.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

/**
 * 视频查看权限响应DTO
 * 包含用户查看视频的权限信息和限制详情
 */
@Data
public class VideoViewPermissionDTO {

    /**
     * 是否可以查看
     */
    @JsonProperty("canView")
    private Boolean canView;

    /**
     * 是否无限制查看
     */
    private Boolean isUnlimited;

    /**
     * 当前查看次数
     */
    private Integer currentViewCount;

    /**
     * 最大查看次数（0表示无限制）
     */
    private Integer maxViewCount;

    /**
     * 时间限制（秒，0表示无限制）
     */
    private Integer timeLimit;

    /**
     * 剩余完整查看次数
     */
    private Integer remainingViews;

    /**
     * 权限信息描述
     */
    private String message;

    /**
     * 是否为限时查看模式
     */
    private Boolean isTimeLimitMode;

    public VideoViewPermissionDTO() {
        this.canView = true;
        this.isUnlimited = false;
        this.currentViewCount = 0;
        this.maxViewCount = 0;
        this.timeLimit = 0;
        this.remainingViews = 0;
        this.isTimeLimitMode = false;
    }

    /**
     * 创建无限制查看的权限对象
     */
    public static VideoViewPermissionDTO createUnlimitedPermission(Integer currentViewCount) {
        VideoViewPermissionDTO dto = new VideoViewPermissionDTO();
        dto.setCanView(true);
        dto.setIsUnlimited(true);
        dto.setCurrentViewCount(currentViewCount);
        dto.setMessage("无限制查看");
        return dto;
    }

    /**
     * 创建完整查看权限对象
     */
    public static VideoViewPermissionDTO createFullViewPermission(Integer currentViewCount, Integer maxViewCount) {
        VideoViewPermissionDTO dto = new VideoViewPermissionDTO();
        dto.setCanView(true);
        dto.setIsUnlimited(false);
        dto.setCurrentViewCount(currentViewCount);
        dto.setMaxViewCount(maxViewCount);
        dto.setRemainingViews(Math.max(0, maxViewCount - currentViewCount));
        dto.setMessage("完整查看模式，剩余" + dto.getRemainingViews() + "次");
        return dto;
    }

    /**
     * 创建限时查看权限对象
     */
    public static VideoViewPermissionDTO createTimeLimitPermission(Integer currentViewCount, Integer maxViewCount, Integer timeLimit) {
        VideoViewPermissionDTO dto = new VideoViewPermissionDTO();
        dto.setCanView(true);
        dto.setIsUnlimited(false);
        dto.setIsTimeLimitMode(true);
        dto.setCurrentViewCount(currentViewCount);
        dto.setMaxViewCount(maxViewCount);
        dto.setTimeLimit(timeLimit);
        dto.setRemainingViews(0);
        dto.setMessage("限时查看模式，每次可查看" + timeLimit + "秒");
        return dto;
    }

    /**
     * 创建禁止查看权限对象
     */
    public static VideoViewPermissionDTO createNoPermission(Integer currentViewCount, Integer maxViewCount) {
        VideoViewPermissionDTO dto = new VideoViewPermissionDTO();
        dto.setCanView(false);
        dto.setIsUnlimited(false);
        dto.setCurrentViewCount(currentViewCount);
        dto.setMaxViewCount(maxViewCount);
        dto.setRemainingViews(0);
        dto.setMessage("已达到查看次数限制，无法继续观看");
        return dto;
    }
}