package com.psg.dlsysinfo.dl_sysinfo_server.entity;

import com.fasterxml.jackson.annotation.JsonManagedReference;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.DynamicUpdate;

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

@Entity
@Table(name = "devices")
@DynamicUpdate
@Getter
@Setter
@NoArgsConstructor
public class Devices {

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

    @ManyToOne
    @JoinColumn(name = "clientId", nullable = false)
    private Client client;

    @Column(unique = true, nullable = false)
    private String hashedHostname;

    @Column(name = "encrypted_hostname", nullable = false)
    private String encryptedHostname;

    @Column(name = "os_name")
    private String osName;

    @Column(name = "os_version")
    private String osVersion;

    @Column(name = "windows_version")
    private String windowsVersion;

    @Column(name = "windows_build")
    private String windowsBuild;

    @Column(name = "os_architecture")
    private String osArchitecture;

    @Column(name = "processor_name")
    private String processorName;

    @Column(name = "processor_architecture")
    private String processorArchitecture;

    @Column(length = 1000, name = "gpu_name")
    private String gpuName;

    @Column(name = "total_memory")
    private String totalMemory;

    @Column(name = "free_disk_space")
    private String freeDiskSpace;

    @Column(name = "ip_address")
    private String ipAddress;

    @Column(name = "mac_address")
    private String macAddress;

    @Column(name = "last_boot_time")
    private String lastBootTime;

    @Column(name = "last_checked_in", nullable = false)
    private LocalDateTime lastCheckedIn = LocalDateTime.now();

    @OneToMany(mappedBy = "device", cascade = CascadeType.ALL, orphanRemoval = true)
    @JsonManagedReference
    private List<Drive> drives;

    @OneToMany(mappedBy = "device", cascade = CascadeType.ALL, orphanRemoval = true)
    @JsonManagedReference
    private List<InstalledSoftware> installedApplications = new ArrayList<>();

    @OneToMany(mappedBy = "device", cascade = CascadeType.ALL, orphanRemoval = true)
    @JsonManagedReference
    private List<IpAddress> ipAddresses = new ArrayList<>();


}
