package com.rj.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import jakarta.validation.constraints.NotBlank;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * 视频合成请求DTO
 * 
 * @author rj
 * @date 2025-01-02
 */
@Data
@Schema(description = "视频合成请求参数")
public class VideoSynthesisRequestDto {

    @Schema(description = "视频名称")
    private String videoName;

    @NotBlank(message = "图片URL不能为空")
    @Schema(description = "图片URL", required = true)
    private String imageUrl;

    @NotBlank(message = "音频URL")
    @Schema(description = "音频URL")
    private String audioUrl;

    @Schema(description = "模板ID", example = "normal")
    private String templateId = "normal";

    @NotBlank(message = "模板URL")
    @Schema(description = "模板URL")
    private String videoTemplateUrl;

    @Schema(description = "使用的模型", example = "liveportrait")
    private String model ;

    @Schema(description = "图片ID", example = "img-12345")
    private String imageId;

    @Schema(description = "音频ID", example ="audio-67890")
    private String audioId;

    @Schema(description = "归属人姓名", example = "张三")
    private String ownerName;

    @Schema(description = "归属人电话", example = "13800138000")
    private String ownerPhone;

    @Schema(description = "模型供应商", example = "dashscope")
    private String modelProvider;


    @Schema(description = "眼部动作频率", example = "0.5")
    private BigDecimal eyeMoveFreq = new BigDecimal("0.5");

    @Schema(description = "视频帧率", example = "30")
    private Integer videoFps = 30;

    @Schema(description = "嘴部动作强度", example = "1.0")
    private BigDecimal mouthMoveStrength = new BigDecimal("1.0");

    @Schema(description = "是否粘贴背景", example = "true")
    private Boolean pasteBack = true;

    @Schema(description = "头部动作强度", example = "0.7")
    private BigDecimal headMoveStrength = new BigDecimal("0.7");

    @Schema(description = "图像区域坐标 [x1, y1, x2, y2]", example = "[302,286,610,593]")
    private String faceBbox;

    @Schema(description = "动态区域坐标 [x1, y1, x2, y2]", example = "[71,9,840,778]")
    private String extBbox;

    @Schema(description = "输入数据", example = "{\"image_url\": \"http://xxx/1.jpg\", \"audio_url\": \"http://xxx/1.wav\"}")
    private Map<String, String> input;

    @Schema(description = "参数配置", example = "{\"template_id\": \"normal\", \"eye_move_freq\": 0.5, \"video_fps\": 30, \"mouth_move_strength\": 1, \"paste_back\": true, \"head_move_strength\": 0.7}")
    private Map<String, Object> parameters;

    /**
     * 构建参数方法
     * 用于构建 input 和 parameters 属性
     */
    public void buildParam() {
        // 构建 input 属性
        this.input = new HashMap<>();
        if (this.imageUrl != null) {
            this.input.put("image_url", this.imageUrl);
        }
        if (this.audioUrl != null) {
            this.input.put("audio_url", this.audioUrl);
        }
        if (this.templateId != null) {
            this.input.put("template_id", this.templateId);
        }
        if (this.templateId != null) {
            this.input.put("driven_id", "mengwa_kaixin");
        }
        if (this.faceBbox != null) {
            this.input.put("face_bbox", this.faceBbox);
        }
        if (this.extBbox != null) {
            this.input.put("ext_bbox", this.extBbox);
        }



        // 构建 parameters 属性
        this.parameters = new HashMap<>();
        if (this.templateId != null) {
            this.parameters.put("video_ratio",  "9:16");
        }
        if (this.eyeMoveFreq != null) {
            this.parameters.put("eye_move_freq", this.eyeMoveFreq);
        }
        if (this.videoFps != null) {
            this.parameters.put("video_fps", this.videoFps);
        }
        if (this.mouthMoveStrength != null) {
            this.parameters.put("mouth_move_strength", this.mouthMoveStrength);
        }
        if (this.pasteBack != null) {
            this.parameters.put("paste_back", this.pasteBack);
        }
        if (this.headMoveStrength != null) {
            this.parameters.put("head_move_strength", this.headMoveStrength);
        }
    }

}
