package com.dora.dto;

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

import java.util.Map;

/**
 * 管理端OSS上传响应DTO
 */
@Data
@Schema(description = "管理端OSS上传响应")
public class AdminOssUploadResponse {

    @Schema(description = "OSS签名版本", example = "OSS4-HMAC-SHA256")
    private String version;

    @Schema(description = "上传策略", example = "eyJleHBpcmF0aW9uIjoiMjAyNC0w...")
    private String policy;

    @Schema(description = "OSS凭证", example = "LTAI5t...")
    private String x_oss_credential;

    @Schema(description = "OSS日期", example = "20241225T120000Z")
    private String x_oss_date;

    @Schema(description = "签名", example = "a1b2c3d4e5f...")
    private String signature;

    @Schema(description = "安全令牌", example = "")
    private String security_token;

    @Schema(description = "上传目录", example = "admin/banners/")
    private String dir;

    @Schema(description = "OSS主机地址", example = "https://bucket.oss-cn-hangzhou.aliyuncs.com")
    private String host;

    @Schema(description = "访问密钥ID", example = "LTAI5t...")
    private String accessKeyId;

    @Schema(description = "管理员ID", example = "admin123")
    private String adminId;

    @Schema(description = "文件名", example = "banner.jpg")
    private String fileName;

    @Schema(description = "文件类型", example = "image")
    private String fileType;

    @Schema(description = "最大文件大小(字节)", example = "52428800")
    private Long maxFileSize;

    @Schema(description = "最大文件大小(MB)", example = "50")
    private Integer maxFileSizeMB;

    @Schema(description = "支持的文件格式", example = "[\"jpg\", \"png\", \"gif\"]")
    private String[] supportedFormats;

    @Schema(description = "上传提示信息")
    private String uploadTips;

    /**
     * 从Map创建响应对象
     */
    public static AdminOssUploadResponse fromMap(Map<String, Object> map) {
        AdminOssUploadResponse response = new AdminOssUploadResponse();
        response.setVersion((String) map.get("version"));
        response.setPolicy((String) map.get("policy"));
        response.setX_oss_credential((String) map.get("x_oss_credential"));
        response.setX_oss_date((String) map.get("x_oss_date"));
        response.setSignature((String) map.get("signature"));
        response.setSecurity_token((String) map.get("security_token"));
        response.setDir((String) map.get("dir"));
        response.setHost((String) map.get("host"));
        response.setAccessKeyId((String) map.get("accessKeyId"));
        response.setAdminId((String) map.get("adminId"));
        response.setFileName((String) map.get("fileName"));
        response.setFileType((String) map.get("fileType"));
        response.setMaxFileSize(((Number) map.get("maxFileSize")).longValue());
        response.setMaxFileSizeMB(((Number) map.get("maxFileSizeMB")).intValue());
        response.setSupportedFormats((String[]) map.get("supportedFormats"));
        response.setUploadTips((String) map.get("uploadTips"));
        return response;
    }
}
