package com.kospo.talk.payload;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.kospo.talk.model.*;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.*;
import jakarta.validation.constraints.Size;
import lombok.*;

import java.util.Date;
import java.util.List;

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

    @Schema(name = "workUrl", description = "업무URL")
    private String workUrl;

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

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

    @Schema(name = "smUsers", description = "유지보수")
    private List<SmUserDto> smUsers;

    @Schema(name = "piUsers", description = "유지보수")
    private List<PIUserDto> piUsers;

    @Schema(name = "manuals", description = "매뉴얼")
    private List<ManualDto> manuals;

    @Schema(name = "workLogo", description = "업무로고")
    private WorkLogoDto workLogo;

    @Schema(name = "workLogo", description = "자동 응답")
    private List<AutoReplyDto> autoReplies;

    @Schema(name = "onlineYn", description = "유지보수 인원이 있는지 여부")
    private Boolean onlineYn;

    @Schema(name = "notStart", description = "시작되지 않은 방 갯수")
    private int notStart;



    public static WorkDto to(Work work) {
        WorkS workS = work.getWorkS();
        return WorkDto.builder()
                .workId(work.getWorkId())
                .workUrl(workS != null ? workS.getWorkUrl() : null)
                .workNm(work.getWorkNm())
                .smUsers(work.getSmUsers() != null ? work.getSmUsers().stream().map(SmUserDto::to).toList() : null)
                .workLogo(work.getWorkLogo() != null ? WorkLogoDto.to(work.getWorkLogo()) : null)
                .build();
    }

}