package com.kt.event.user.entity;

import com.kt.event.common.entity.BaseTimeEntity;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.GenericGenerator;

import java.util.UUID;

/**
 * 매장 엔티티
 *
 * 소상공인 매장 정보를 저장하는 엔티티
 *
 * @author Backend Developer
 * @since 1.0
 */
@Entity
@Table(name = "stores")
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Builder
public class Store extends BaseTimeEntity {

    /**
     * 매장 ID (Primary Key)
     */
    @Id
    @GeneratedValue(generator = "uuid2")
    @GenericGenerator(name = "uuid2", strategy = "uuid2")
    @Column(name = "store_id", columnDefinition = "uuid")
    private UUID id;

    /**
     * 매장명
     */
    @Column(name = "name", nullable = false, length = 100)
    private String name;

    /**
     * 업종
     */
    @Column(name = "industry", length = 50)
    private String industry;

    /**
     * 주소
     */
    @Column(name = "address", nullable = false, length = 255)
    private String address;

    /**
     * 영업시간
     */
    @Column(name = "business_hours", length = 255)
    private String businessHours;

    /**
     * 사용자 정보 (One-to-One)
     */
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", nullable = false)
    private User user;

    /**
     * 사용자 연결 (내부용)
     *
     * @param user 사용자
     */
    void setUser(User user) {
        this.user = user;
    }

    /**
     * 매장 정보 수정
     *
     * @param name 매장명
     * @param industry 업종
     * @param address 주소
     * @param businessHours 영업시간
     */
    public void updateInfo(String name, String industry, String address, String businessHours) {
        if (name != null) {
            this.name = name;
        }
        if (industry != null) {
            this.industry = industry;
        }
        if (address != null) {
            this.address = address;
        }
        if (businessHours != null) {
            this.businessHours = businessHours;
        }
    }
}
