package com.kospo.talk.model;

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

@Getter
@Setter
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Table(name = "sm_user")
public class SmUser {
    @EmbeddedId
    private SmUserId id;

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

    @Size(max = 50)
    @Column(name = "work_nm", length = 50)
    private String workNm;

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


    public static SmUser to(SmUserDto smUserDto) {
        return SmUser.builder()
                .id(SmUserId.builder()
                        .workId(smUserDto.getWorkId())
                        .sabun(smUserDto.getSabun()).build()
                )
                .workNm(smUserDto.getWorkNm())
                .name(smUserDto.getName()).build();
    }

}