package com.bankaudit.model;

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

import javax.persistence.*;

@Entity
@Table(name = "app_issues")
public class IssueReport {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "entity_name", nullable = false)
    private String entityName;

    @Column(name = "legal_entity_code", nullable = false)
    private String legalEntityCode;

    @Column(name = "user_id", nullable = false)
    private String userId;

    @Column(name = "user_email", nullable = false)
    private String userEmail;

    @Column(name = "user_role", nullable = false)
    private String userRole;

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

    @Column(name = "issue_description", columnDefinition = "TEXT", nullable = false)
    private String issueDescription;

    @Column(name = "file_name")
    private String fileName;

    @Column(name = "file_path")
    private String filePath;

    @Column(name = "file_type")
    private String fileType;

    @Column(name = "status", nullable = false)
    private String status = "Open";

    @Column(name = "created_at", updatable = false)
    private LocalDateTime createdAt = LocalDateTime.now();

    @Column(name = "updated_at")
    private LocalDateTime updatedAt = LocalDateTime.now();

    @Column(name = "unit_id")
    private String unitId;
    @Column(name = "financial_year")
    private String financialYear;
    @Column(name = "issue_type")
     private String issueType;

    @Column(name = "acted_on_date")
    private Date actedOnByTeam;


        // === New Field: List of AppIssueFiles ===
 @OneToMany(mappedBy = "issueReport", cascade = CascadeType.ALL, orphanRemoval = true)
private List<AppIssueFile> issueFiles = new ArrayList<>();


    public List<AppIssueFile> getIssueFiles() {
        return issueFiles;
    }

    public void setIssueFiles(List<AppIssueFile> issueFiles) {
        this.issueFiles = issueFiles;
    }

    @PreUpdate
    public void setUpdatedAt() {
        this.updatedAt = LocalDateTime.now();
    }

    @Transient
    private String userName;

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }
    public Long getId() {
        return id;
    }

    public String getEntityName() {
        return entityName;
    }

    public void setEntityName(String entityName) {
        this.entityName = entityName;
    }

    public String getLegalEntityCode() {
        return legalEntityCode;
    }

    public void setLegalEntityCode(String legalEntityCode) {
        this.legalEntityCode = legalEntityCode;
    }

    public String getUserId() {
        return userId;
    }

    public String getFinancialYear() {
       return financialYear;
    }

     public void setFinancialYear(String financialYear) {
       this.financialYear = financialYear;
    }
    public void setUserId(String userId) {
        this.userId = userId;
    }



    public String getUserEmail() {
        return userEmail;
    }

    public void setUserEmail(String userEmail) {
        this.userEmail = userEmail;
    }

    public String getUserRole() {
        return userRole;
    }

    public void setUserRole(String userRole) {
        this.userRole = userRole;
    }

    public String getProcess() {
        return process;
    }

    public void setProcess(String process) {
        this.process = process;
    }

    public String getIssueDescription() {
        return issueDescription;
    }

    public void setIssueDescription(String issueDescription) {
        this.issueDescription = issueDescription;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public String getFileType() {
        return fileType;
    }

    public void setFileType(String fileType) {
        this.fileType = fileType;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public LocalDateTime getCreatedAt() {
        return createdAt;
    }

    public LocalDateTime getUpdatedAt() {
        return updatedAt;
    }
    public String getUnitId() {
        return unitId;
    }
    public void setUnitId(String unitId) {
        this.unitId = unitId;
    }

    public String getIssueType() {
    return issueType;
}

public void setIssueType(String issueType) {
    this.issueType = issueType;
}

public Date getActedOnByTeam() {
    return actedOnByTeam;
}

public void setActedOnByTeam(Date actedOnByTeam) {
    this.actedOnByTeam = actedOnByTeam;
}

}
