package com.kospo.talk.model;

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

@Getter
@Setter
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Table(name = "pi_user")
public class PiUser {
    @EmbeddedId
    private PiUserId 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 PiUser to(PIUserDto piUserDto) {
        return PiUser.builder()
                .id(PiUserId.builder()
                        .workId(piUserDto.getWorkId())
                        .sabun(piUserDto.getSabun()).build()
                )
                .workNm(piUserDto.getWorkNm())
                .name(piUserDto.getName()).build();
    }

}