package com.kospo.talk.payload;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.kospo.talk.model.Favorite;
import com.kospo.talk.model.WorkLogo;
import com.kospo.talk.model.WorkS;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

import java.io.Serializable;

/**
 * DTO for {@link com.kospo.talk.model.Favorite}
 */
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@JsonIgnoreProperties(ignoreUnknown = true)
@Schema(name = "FavoriteDto", description = "즐겨찾기")
public class FavoriteDto implements Serializable {
    @Schema(name = "sabun", description = "사번")
    String sabun;
    @Schema(name = "workId", description = "업무아이디")
    String workId;
    @Schema(name = "workNm", description = "업무명")
    String workNm;
    @Schema(name = "url", description = "url")
    String url;
    WorkLogoDto workLogo;

    public static FavoriteDto to(Favorite favorite) {
        WorkS workS = favorite.getWork().getWorkS();
        WorkLogo workLogo = favorite.getWork().getWorkLogo();
        return FavoriteDto.builder()
                .workId(favorite.getId().getWorkId())
                .sabun(favorite.getId().getSabun())
                .url(workS.getWorkUrl())
                .workLogo(workLogo == null ? null : WorkLogoDto.to(workLogo))
                .workNm(favorite.getWork().getWorkNm()).build();
    }
}