package com.kospo.talk.payload;

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

import java.util.List;
import java.util.stream.Collectors;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@JsonIgnoreProperties(ignoreUnknown = true)
@Schema(name = "WorkCategoryDto", description = "업무카테고리 관리")
public class WorkCategoryDto {
    @Schema(name = "workId", description = "업무아이디")
    private String workId;

    @Schema(name = "workNm", description = "업무이름")
    private String workNm;

    @Schema(name = "workFullNm", description = "업무 전체 이름")
    private String workFullNm;

    @Schema(name = "gubun", description = "레벨")
    private char gubun;

    @Schema(name = "pWorkId", description = "상위업무아이디")
    private String pWorkId;

    private List<SmUserDto> smUsers;



    public static WorkCategoryDto to(Work work) {

        return WorkCategoryDto.builder()
                .workId(work.getWorkId())
                .workNm(work.getWorkNm())
                .gubun(work.getGubun())
                .pWorkId(work.getPWorkId())
                .smUsers(work.getSmUsers() == null ? null : work.getSmUsers().stream().map(SmUserDto::to).collect(Collectors.toList()))
                .build();
    }

}