package com.kospo.talk.model;

import com.kospo.talk.payload.ManualDto;
import jakarta.persistence.*;
import jakarta.validation.constraints.Size;
import lombok.*;

import java.time.LocalDateTime;
import java.util.Date;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "manual")
public class Manual {
    @EmbeddedId
    private ManualId id;

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "work_id", nullable = false, updatable = false, insertable = false)
    private Work work;

    @Column(name = "version")
    private String version;

    @Size(max = 4)
    @Column(name = "type", length = 4)
    private String type;

    @Size(max = 100)
    @Column(name = "onm", length = 100)
    private String onm;

    @Size(max = 200)
    @Column(name = "path", length = 200)
    private String path;

    @Column(name = "size")
    private Integer size;

    @Column(name = "ins_date")
    private LocalDateTime insDate;

    @Column(name = "delete_yn")
    private Boolean deleteYn;

    public static Manual to(ManualDto manualDto) {
        return Manual.builder()
                .id(ManualId.builder()
                        .workId(manualDto.getWorkId())
                        .vnm(manualDto.getVnm()).build()
                )
                .version(manualDto.getVersion())
                .type(manualDto.getType())
                .onm(manualDto.getOnm())
                .path(manualDto.getPath())
                .deleteYn(manualDto.getDeleteYn())
                .insDate(manualDto.getInsDate()).build();
    }
}