package com.multictrl.modules.business.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.*;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;

/**
 * 喊话器内容
 *
 * @author Sdy
 * @since 1.0.0 2026-05-08
 */
@Data
@Schema(name = "喊话器内容")
public class SpeakerDTO implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @Schema(description = "标识")
    private Long id;

    @NotNull(message = "类型不能为空")
    @Min(value = 1, message = "类型错误")
    @Max(value = 2, message = "类型错误")
    @Schema(description = "类型 1:文本 2:音频")
    private Integer type;

    @NotBlank(message = "机场编号不能为空")
    @Schema(description = "机场编号")
    private String dockSn;

    @NotBlank(message = "模版名称不能为空")
    @Schema(description = "模版名称")
    private String name;

    @Schema(description = "文本内容")
    private String textContent;

    @Schema(description = "源音频文件地址")
    private String mediaPath;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @Schema(description = "创建时间")
    private Date createDate;

    @JsonIgnore
    @Schema(hidden = true)
    @AssertTrue(message = "源音频文件不能为空")
    public boolean isMediaPathValid() {
        if (type == 2) {
            return StringUtils.isNotBlank(mediaPath);
        }

        return true;
    }

    @JsonIgnore
    @Schema(hidden = true)
    @AssertTrue(message = "文本内容不能为空")
    public boolean isTextContentValid() {
        if (type == 1) {
            return StringUtils.isNotBlank(textContent);
        }

        return true;
    }
}
