/* src/bazaar.p/bz-flathub-curated-selection.c
 *
 * Copyright 2026 AUTOGEN
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include "src/bazaar.p/bz-flathub-curated-selection.h"



struct _BzFlathubCuratedSelection
{
  GObject parent_instance;

  char *theme_key;
  char *slot;
  GtkStringList *apps;
  BzApplicationMapFactory *map_factory;
};

G_DEFINE_FINAL_TYPE (BzFlathubCuratedSelection, bz_flathub_curated_selection, G_TYPE_OBJECT);

enum
{
  PROP_0,

  PROP_THEME_KEY,
  PROP_SLOT,
  PROP_APPS,
  PROP_MAP_FACTORY,

  LAST_PROP
};
static GParamSpec *props[LAST_PROP] = { 0 };

static void
bz_flathub_curated_selection_dispose (GObject *object)
{
  BzFlathubCuratedSelection *self = BZ_FLATHUB_CURATED_SELECTION (object);

  g_clear_pointer (&self->theme_key, g_free);
  g_clear_pointer (&self->slot, g_free);
  g_clear_pointer (&self->apps, g_object_unref);
  g_clear_pointer (&self->map_factory, g_object_unref);

  G_OBJECT_CLASS (bz_flathub_curated_selection_parent_class)->dispose (object);
}

static void
bz_flathub_curated_selection_get_property (GObject    *object,
                       guint       prop_id,
                       GValue     *value,
                       GParamSpec *pspec)
{
  BzFlathubCuratedSelection *self = BZ_FLATHUB_CURATED_SELECTION (object);

  switch (prop_id)
    {
    case PROP_THEME_KEY:
      g_value_set_string (value, bz_flathub_curated_selection_get_theme_key (self));
      break;
    case PROP_SLOT:
      g_value_set_string (value, bz_flathub_curated_selection_get_slot (self));
      break;
    case PROP_APPS:
      g_value_set_object (value, bz_flathub_curated_selection_get_apps (self));
      break;
    case PROP_MAP_FACTORY:
      g_value_set_object (value, bz_flathub_curated_selection_get_map_factory (self));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}

static void
bz_flathub_curated_selection_set_property (GObject      *object,
                       guint         prop_id,
                       const GValue *value,
                       GParamSpec   *pspec)
{
  BzFlathubCuratedSelection *self = BZ_FLATHUB_CURATED_SELECTION (object);

  switch (prop_id)
    {
    case PROP_THEME_KEY:
      bz_flathub_curated_selection_set_theme_key (self, g_value_get_string (value));
      break;
    case PROP_SLOT:
      bz_flathub_curated_selection_set_slot (self, g_value_get_string (value));
      break;
    case PROP_APPS:
      bz_flathub_curated_selection_set_apps (self, g_value_get_object (value));
      break;
    case PROP_MAP_FACTORY:
      bz_flathub_curated_selection_set_map_factory (self, g_value_get_object (value));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}

static void
bz_flathub_curated_selection_class_init (BzFlathubCuratedSelectionClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);



  object_class->set_property = bz_flathub_curated_selection_set_property;
  object_class->get_property = bz_flathub_curated_selection_get_property;
  object_class->dispose      = bz_flathub_curated_selection_dispose;

  props[PROP_THEME_KEY] =
      g_param_spec_string (
          "theme-key",
          NULL, NULL, NULL,
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);

  props[PROP_SLOT] =
      g_param_spec_string (
          "slot",
          NULL, NULL, NULL,
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);

  props[PROP_APPS] =
      g_param_spec_object (
          "apps",
          NULL, NULL,
          GTK_TYPE_STRING_LIST,
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);

  props[PROP_MAP_FACTORY] =
      g_param_spec_object (
          "map-factory",
          NULL, NULL,
          BZ_TYPE_APPLICATION_MAP_FACTORY,
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);

  g_object_class_install_properties (object_class, LAST_PROP, props);
}

static void
bz_flathub_curated_selection_init (BzFlathubCuratedSelection *self)
{
}

BzFlathubCuratedSelection *
bz_flathub_curated_selection_new (void){
  return g_object_new (BZ_TYPE_FLATHUB_CURATED_SELECTION, NULL);
}

const char *
bz_flathub_curated_selection_get_theme_key (BzFlathubCuratedSelection *self){
  g_return_val_if_fail (BZ_IS_FLATHUB_CURATED_SELECTION (self), NULL);
  return self->theme_key;
}

const char *
bz_flathub_curated_selection_get_slot (BzFlathubCuratedSelection *self){
  g_return_val_if_fail (BZ_IS_FLATHUB_CURATED_SELECTION (self), NULL);
  return self->slot;
}

GtkStringList *
bz_flathub_curated_selection_get_apps (BzFlathubCuratedSelection *self){
  g_return_val_if_fail (BZ_IS_FLATHUB_CURATED_SELECTION (self), NULL);
  return self->apps;
}

BzApplicationMapFactory *
bz_flathub_curated_selection_get_map_factory (BzFlathubCuratedSelection *self){
  g_return_val_if_fail (BZ_IS_FLATHUB_CURATED_SELECTION (self), NULL);
  return self->map_factory;
}

void
bz_flathub_curated_selection_set_theme_key (BzFlathubCuratedSelection *self,
    const char *theme_key){
  g_return_if_fail (BZ_IS_FLATHUB_CURATED_SELECTION (self));

  if (theme_key == self->theme_key || (theme_key != NULL && self->theme_key != NULL && g_strcmp0(theme_key, self->theme_key) == 0))
    return;

  g_clear_pointer (&self->theme_key, g_free);
  if (theme_key != NULL)
    self->theme_key = g_strdup (theme_key);

  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_THEME_KEY]);
}

void
bz_flathub_curated_selection_set_slot (BzFlathubCuratedSelection *self,
    const char *slot){
  g_return_if_fail (BZ_IS_FLATHUB_CURATED_SELECTION (self));

  if (slot == self->slot || (slot != NULL && self->slot != NULL && g_strcmp0(slot, self->slot) == 0))
    return;

  g_clear_pointer (&self->slot, g_free);
  if (slot != NULL)
    self->slot = g_strdup (slot);

  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_SLOT]);
}

void
bz_flathub_curated_selection_set_apps (BzFlathubCuratedSelection *self,
    GtkStringList *apps){
  g_return_if_fail (BZ_IS_FLATHUB_CURATED_SELECTION (self));

  if (apps == self->apps)
    return;

  g_clear_pointer (&self->apps, g_object_unref);
  if (apps != NULL)
    self->apps = g_object_ref (apps);

  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_APPS]);
}

void
bz_flathub_curated_selection_set_map_factory (BzFlathubCuratedSelection *self,
    BzApplicationMapFactory *map_factory){
  g_return_if_fail (BZ_IS_FLATHUB_CURATED_SELECTION (self));

  if (map_factory == self->map_factory)
    return;

  g_clear_pointer (&self->map_factory, g_object_unref);
  if (map_factory != NULL)
    self->map_factory = g_object_ref (map_factory);

  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_MAP_FACTORY]);
}

void
bz_flathub_curated_selection_set_theme_key_take (BzFlathubCuratedSelection *self,
    char *theme_key){
  g_return_if_fail (BZ_IS_FLATHUB_CURATED_SELECTION (self));

  if (theme_key != NULL && self->theme_key != NULL && g_strcmp0(theme_key, self->theme_key) == 0){
    g_free (theme_key);
    return;
  }

  g_clear_pointer (&self->theme_key, g_free);
  if (theme_key != NULL)
    self->theme_key = theme_key;

  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_THEME_KEY]);
}

void
bz_flathub_curated_selection_set_slot_take (BzFlathubCuratedSelection *self,
    char *slot){
  g_return_if_fail (BZ_IS_FLATHUB_CURATED_SELECTION (self));

  if (slot != NULL && self->slot != NULL && g_strcmp0(slot, self->slot) == 0){
    g_free (slot);
    return;
  }

  g_clear_pointer (&self->slot, g_free);
  if (slot != NULL)
    self->slot = slot;

  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_SLOT]);
}

/* End of src/bazaar.p/bz-flathub-curated-selection.c */
