/* src/bazaar.p/bz-curated-row.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-curated-row.h"



struct _BzCuratedRow
{
  GObject parent_instance;

  BzCuratedSection *section;
  BzCuratedFeaturedCarousel *featured_carousel;
  BzCuratedBanner *banner;
  BzCuratedArticlesInfo *articles;
};

G_DEFINE_FINAL_TYPE (BzCuratedRow, bz_curated_row, G_TYPE_OBJECT);

enum
{
  PROP_0,

  PROP_SECTION,
  PROP_FEATURED_CAROUSEL,
  PROP_BANNER,
  PROP_ARTICLES,

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

static void
bz_curated_row_dispose (GObject *object)
{
  BzCuratedRow *self = BZ_CURATED_ROW (object);

  g_clear_pointer (&self->section, g_object_unref);
  g_clear_pointer (&self->featured_carousel, g_object_unref);
  g_clear_pointer (&self->banner, g_object_unref);
  g_clear_pointer (&self->articles, g_object_unref);

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

static void
bz_curated_row_get_property (GObject    *object,
                       guint       prop_id,
                       GValue     *value,
                       GParamSpec *pspec)
{
  BzCuratedRow *self = BZ_CURATED_ROW (object);

  switch (prop_id)
    {
    case PROP_SECTION:
      g_value_set_object (value, bz_curated_row_get_section (self));
      break;
    case PROP_FEATURED_CAROUSEL:
      g_value_set_object (value, bz_curated_row_get_featured_carousel (self));
      break;
    case PROP_BANNER:
      g_value_set_object (value, bz_curated_row_get_banner (self));
      break;
    case PROP_ARTICLES:
      g_value_set_object (value, bz_curated_row_get_articles (self));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}

static void
bz_curated_row_set_property (GObject      *object,
                       guint         prop_id,
                       const GValue *value,
                       GParamSpec   *pspec)
{
  BzCuratedRow *self = BZ_CURATED_ROW (object);

  switch (prop_id)
    {
    case PROP_SECTION:
      bz_curated_row_set_section (self, g_value_get_object (value));
      break;
    case PROP_FEATURED_CAROUSEL:
      bz_curated_row_set_featured_carousel (self, g_value_get_object (value));
      break;
    case PROP_BANNER:
      bz_curated_row_set_banner (self, g_value_get_object (value));
      break;
    case PROP_ARTICLES:
      bz_curated_row_set_articles (self, g_value_get_object (value));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}

static void
bz_curated_row_class_init (BzCuratedRowClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);



  object_class->set_property = bz_curated_row_set_property;
  object_class->get_property = bz_curated_row_get_property;
  object_class->dispose      = bz_curated_row_dispose;

  props[PROP_SECTION] =
      g_param_spec_object (
          "section",
          NULL, NULL,
          BZ_TYPE_CURATED_SECTION,
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);

  props[PROP_FEATURED_CAROUSEL] =
      g_param_spec_object (
          "featured-carousel",
          NULL, NULL,
          BZ_TYPE_CURATED_FEATURED_CAROUSEL,
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);

  props[PROP_BANNER] =
      g_param_spec_object (
          "banner",
          NULL, NULL,
          BZ_TYPE_CURATED_BANNER,
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);

  props[PROP_ARTICLES] =
      g_param_spec_object (
          "articles",
          NULL, NULL,
          BZ_TYPE_CURATED_ARTICLES_INFO,
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);

  g_object_class_install_properties (object_class, LAST_PROP, props);
}

static void
bz_curated_row_init (BzCuratedRow *self)
{
}

BzCuratedRow *
bz_curated_row_new (void){
  return g_object_new (BZ_TYPE_CURATED_ROW, NULL);
}

BzCuratedSection *
bz_curated_row_get_section (BzCuratedRow *self){
  g_return_val_if_fail (BZ_IS_CURATED_ROW (self), NULL);
  return self->section;
}

BzCuratedFeaturedCarousel *
bz_curated_row_get_featured_carousel (BzCuratedRow *self){
  g_return_val_if_fail (BZ_IS_CURATED_ROW (self), NULL);
  return self->featured_carousel;
}

BzCuratedBanner *
bz_curated_row_get_banner (BzCuratedRow *self){
  g_return_val_if_fail (BZ_IS_CURATED_ROW (self), NULL);
  return self->banner;
}

BzCuratedArticlesInfo *
bz_curated_row_get_articles (BzCuratedRow *self){
  g_return_val_if_fail (BZ_IS_CURATED_ROW (self), NULL);
  return self->articles;
}

void
bz_curated_row_set_section (BzCuratedRow *self,
    BzCuratedSection *section){
  g_return_if_fail (BZ_IS_CURATED_ROW (self));

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

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

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

void
bz_curated_row_set_featured_carousel (BzCuratedRow *self,
    BzCuratedFeaturedCarousel *featured_carousel){
  g_return_if_fail (BZ_IS_CURATED_ROW (self));

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

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

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

void
bz_curated_row_set_banner (BzCuratedRow *self,
    BzCuratedBanner *banner){
  g_return_if_fail (BZ_IS_CURATED_ROW (self));

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

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

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

void
bz_curated_row_set_articles (BzCuratedRow *self,
    BzCuratedArticlesInfo *articles){
  g_return_if_fail (BZ_IS_CURATED_ROW (self));

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

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

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



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