package mx.gob.jumapacelaya.models;

import java.sql.Date;
import java.time.LocalDate;

public class Ticket {
    private final int id;
    private final String subject;
    private final String description;
    private final String status;
    private final LocalDate dateCreate;
    private LocalDate dateClose;
    private User author;
    private Integer trackerId;
    private String type;



    public Ticket(int id, String subject, String description, String status, String dateCreate, String dateClose, Integer trackerId, String type) {
        this.id = id;
        this.subject = subject;
        this.description = description;
        this.status = status;
        // Manejo de la fecha de creación
        if (dateCreate != null && !dateCreate.isEmpty()) {
            this.dateCreate = LocalDate.parse(dateCreate); // Solo se parsea si no está vacío
        } else {
            this.dateCreate = null; // Si está vacío, asignar null
        }

        // Manejo de la fecha de cierre
        if (dateClose != null && !dateClose.isEmpty()) {
            this.dateClose = LocalDate.parse(dateClose); // Solo se parsea si no está vacío
        } else {
            this.dateClose = null; // Si está vacío, asignar null
        }
        this.author = author;
        this.trackerId = trackerId;
        this.type = type;
    }

    public int getId() {
        return id;
    }

    public String getSubject() {
        return subject;
    }

    public String getDescription() {
        return description;
    }

    public String getStatus() {
        return status;
    }

    public User getAuthor() {
        return author;
    }

    public void setAuthor(User author) {
        this.author = author;
    }

    public Date getDateCreate() {
        return java.sql.Date.valueOf(this.dateCreate);
    }

    public Integer getTrackerId() {
        return trackerId;
    }

    public void setTrackerId(Integer tipoId) {
        this.trackerId = tipoId;
    }

    public LocalDate getDateClose() {
        return dateClose;
    }

    public void setDateClose(LocalDate dateClose) {
        this.dateClose = dateClose;
    }

    public void setType(String type) {
        this.type = type;
    }


    public static class User {
        private String username;

        public User(String username) {
            this.username = username;
        }

        public String getUsername() {
            return username;
        }

        public void setUsername(String username) {
            this.username = username;
        }
    }


    public String tiempoEst(Integer trackerId) {
        if (trackerId == null) {
            return "Desconocido";
        }

        switch (trackerId) {
            case 5,16,17:
                return "2 horas max.";

            case 4,13,14:
                return "2 a 6 horas";

            case 6,7,9,10,11,15:
                return "1 a 2 Dias";

            default:
                return "N/A";
        }
    }


    public String getType() {
        if (trackerId == null) {
            return "Desconocido";
        }
        return switch (trackerId) {
            case 4 -> "Acceso/Permiso/Bajas";
            case 5 -> "Soporte de Software";
            case 6 -> "Capacitacion de Software";
            case 7 -> "Configuracion de Software";
            case 8 -> "Desarrollo de Software";
            case 9 -> "Digitalizacion GIS";
            case 10 -> "Documento";
            case 11 -> "Reporte";
            case 13 -> "DML";
            case 14 -> "DCL";
            case 15 -> "DDL";
            case 16 -> "Mantenimiento Correctivo";
            case 17 -> "Actividad";
            default -> "N/A";
        };
    }
}
