package ru.soune.nocopy.entity.company;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import jakarta.validation.constraints.Size;
import lombok.*;
import org.springframework.data.annotation.CreatedDate;
import ru.soune.nocopy.entity.tarif.TariffInfo;
import ru.soune.nocopy.entity.user.User;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Entity
@AllArgsConstructor
@NoArgsConstructor
@Getter @Setter
@Table(name = "company")
public class Company {

    @Id
    @GeneratedValue(strategy = GenerationType.UUID)
    private String id;

    @Column(name = "company_name")
    private String companyName;

    @Column(name = "address")
    private String address;

    @Column(name = "phone")
    private String phone;

    @Column(name = "inn", unique = true)
    private String inn;

    @CreatedDate
    @Column(name = "register_date", updatable = false, nullable = false)
    private LocalDateTime registerDate = LocalDateTime.now();

    @Column(name = "update_date")
    private LocalDateTime updateDate;

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

    @OneToMany(mappedBy = "company")
    @JsonIgnore
    @ToString.Exclude
    private List<User> users = new ArrayList<>();

    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "tariff_info_id")
    private TariffInfo tariffInfo;
}
