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;

    // V11.0: Liste av minutter (f.eks [15, 60])
    @SerializedName("reminders")
    private List<Integer> reminders = new ArrayList<>();

    // 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 : ""; }

    // Henter listen. Hvis den er null (gamle data), returner tom liste.
    public List<Integer> getReminders() {
        return reminders != null ? reminders : new ArrayList<>();
    }

// --- KOMPATIBILITETS-METODER (For å fikse build-feil i CalendarManager og Worker) ---

    // Brukes av CalendarManager.java for lokale events
    public void setReminderMinutes(int minutes) {
        this.reminders = new ArrayList<>();
        if (minutes > 0) {
            this.reminders.add(minutes);
        }
    }

    // Brukes hvis gammel kode prøver å hente ett tall. Returnerer det første i listen.
    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; }
}