package com.yaoai.api.dto.asset;

import com.yaoai.domain.entity.GlobalAsset;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

@Data
public class GlobalAssetDTO {

    private Long id;
    private Long creatorUserId;
    private String name;
    private String assetType;
    private String libraryType;
    private List<String> tags;
    private String imageUrl;
    private String imageTosKey;
    private String description;
    private boolean favorite;
    private LocalDateTime createdAt;

    public static GlobalAssetDTO from(GlobalAsset a) {
        GlobalAssetDTO dto = new GlobalAssetDTO();
        dto.setId(a.getId());
        dto.setCreatorUserId(a.getCreatorUserId());
        dto.setName(a.getName());
        dto.setAssetType(a.getAssetType());
        dto.setLibraryType(a.getLibraryType());
        dto.setTags(a.getTags() != null && !a.getTags().isBlank()
                ? Arrays.asList(a.getTags().split(","))
                : List.of());
        dto.setImageUrl(a.getImageUrl());
        dto.setImageTosKey(a.getImageTosKey());
        dto.setDescription(a.getDescription());
        dto.setFavorite(Integer.valueOf(1).equals(a.getIsFavorite()));
        dto.setCreatedAt(a.getCreatedAt());
        return dto;
    }
}
