package com.kbs.kbsintranett;

import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class CalendarEvent implements Serializable  {
    @SerializedName("id")
    private String id;

    @SerializedName("title")
    private String title;

    @SerializedName("start_date")
    private String rawDate;

    @SerializedName("end_date")
    private String rawEndDate;

    @SerializedName("description")
    private String description;

    @SerializedName("location")
    private String location;

    @SerializedName("reminders")
    private List<Integer> reminders = new ArrayList<>();

    // NYE FELTER V12.2
    @SerializedName("calendar_name")
    private String calendarName;

    @SerializedName("calendar_color")
    private String calendarColor;

    // UI-hjelpefelter
    private String day;
    private String month;
    private String time;

    // Konstruktør
    public CalendarEvent(String title, String rawDate, String rawEndDate, String description, String location) {
        this.title = title;
        this.rawDate = rawDate;
        this.rawEndDate = rawEndDate;
        this.description = description;
        this.location = location;
    }

    public String getId() { return id; }
    public String getTitle() { return title; }
    public String getRawDate() { return rawDate; }
    public String getRawEndDate() { return rawEndDate; }
    public String getDescription() { return description != null ? description : ""; }
    public String getLocation() { return location != null ? location : ""; }

    public List<Integer> getReminders() {
        return reminders != null ? reminders : new ArrayList<>();
    }

    // NYE GETTERS/SETTERS
    public String getCalendarName() { return calendarName != null ? calendarName : "Ukjent"; }
    public void setCalendarName(String name) { this.calendarName = name; }

    public String getCalendarColor() { return calendarColor != null ? calendarColor : "#888888"; }
    public void setCalendarColor(String color) { this.calendarColor = color; }

    // --- KOMPATIBILITETS-METODER ---

    // Denne brukes for enkle varsler
    public void setReminderMinutes(int minutes) {
        this.reminders = new ArrayList<>();
        if (minutes > 0) {
            this.reminders.add(minutes);
        }
    }

    // NY METODE (Den som manglet og forårsaket krasj)
    // Lar oss sette hele listen med varsler på en gang
    public void setRemindersList(List<Integer> reminders) {
        this.reminders = reminders != null ? new ArrayList<>(reminders) : new ArrayList<>();
    }

    public int getReminderMinutes() {
        if (reminders != null && !reminders.isEmpty()) {
            return reminders.get(0);
        }
        return 0;
    }

    // --- UI SETTERS/GETTERS ---
    public String getDay() { return day; }
    public void setDay(String day) { this.day = day; }
    public String getMonth() { return month; }
    public void setMonth(String month) { this.month = month; }
    public String getTime() { return time; }
    public void setTime(String time) { this.time = time; }
}