package com.pharmacopoeia.entity;

import jakarta.persistence.*;
import lombok.*;

import java.time.Instant;

@Entity
@Table(name = "brands")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Brand {

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

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

    @Column(name = "function_indication", columnDefinition = "text")
    private String functionIndication;

    @Column(name = "usage_dosage", columnDefinition = "text")
    private String usageDosage;

    @Column(columnDefinition = "text")
    private String contraindication;

    @Column(columnDefinition = "text")
    private String ingredients;

    @Column(columnDefinition = "text")
    private String properties;

    @Column(columnDefinition = "text")
    private String specification;

    @Column(name = "adverse_reactions", columnDefinition = "text")
    private String adverseReactions;

    @Column(columnDefinition = "text")
    private String precautions;

    @Column(name = "execution_standard", columnDefinition = "text")
    private String executionStandard;

    @Column(columnDefinition = "text")
    private String storage;

    @Column(name = "jump_url", length = 500)
    private String jumpUrl;

    @Column(length = 500)
    private String description;

    @Column(name = "sort_order", nullable = false)
    @Builder.Default
    private Integer sortOrder = 0;

    @Column(name = "is_active", nullable = false)
    @Builder.Default
    private Boolean isActive = true;

    @Column(name = "created_at", updatable = false)
    private Instant createdAt;

    @Column(name = "updated_at")
    private Instant updatedAt;

    @PrePersist
    void onCreate() {
        if (createdAt == null) createdAt = Instant.now();
        if (updatedAt == null) updatedAt = Instant.now();
    }

    @PreUpdate
    void onUpdate() {
        updatedAt = Instant.now();
    }
}
