package dev.bytevibe.hyperpoint;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import java.io.Serializable;

/**
 * 表示整个演示文稿
 */
public class Presentation implements Serializable {
    private String name;
    private ObservableList<Slide> slides;
    private int currentSlideIndex;

    public Presentation() {
        this.name = "新演示文稿";
        this.slides = FXCollections.observableArrayList();
        this.currentSlideIndex = 0;
    }

    public Presentation(String name) {
        this.name = name;
        this.slides = FXCollections.observableArrayList();
        this.currentSlideIndex = 0;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public ObservableList<Slide> getSlides() {
        return slides;
    }

    public int getCurrentSlideIndex() {
        return currentSlideIndex;
    }

    public void setCurrentSlideIndex(int index) {
        if (index >= 0 && index < slides.size()) {
            this.currentSlideIndex = index;
        }
    }

    public Slide getCurrentSlide() {
        if (currentSlideIndex >= 0 && currentSlideIndex < slides.size()) {
            return slides.get(currentSlideIndex);
        }
        return null;
    }

    /**
     * 添加新幻灯片
     */
    public void addSlide(Slide slide) {
        slides.add(slide);
    }

    /**
     * 删除指定索引的幻灯片
     */
    public boolean removeSlide(int index) {
        if (slides.size() > 1 && index >= 0 && index < slides.size()) {
            slides.remove(index);
            if (currentSlideIndex >= slides.size()) {
                currentSlideIndex = slides.size() - 1;
            }
            return true;
        }
        return false;
    }
}

