package com.devjob.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

/**
 * 회사.
 *
 * EP13: Job과 1:N(@OneToMany, mappedBy="company") 양방향 연관관계.
 * 연관관계의 주인은 Job(FK를 가진 쪽)이며, Company는 조회 편의를 위한 컬렉션만 가진다.
 * 양방향 연관관계에서는 @ToString 순환 참조에 주의해야 하므로, 이 엔티티는 toString을 생성하지 않는다(Lombok @Getter만 사용).
 */
@Entity
@Table(name = "company")
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@EntityListeners(AuditingEntityListener.class)
public class Company {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(nullable = false, length = 100)
    private String name;

    @Column(length = 100)
    private String location;

    @OneToMany(mappedBy = "company")
    private List<Job> jobs = new ArrayList<>();

    @CreatedDate
    @Column(updatable = false)
    private LocalDateTime createdAt;

    @Builder
    public Company(String name, String location) {
        this.name = name;
        this.location = location;
    }
}
