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



struct _BzCuratedArticle
{
  GObject parent_instance;

  char *title;
  char *subtitle;
  char *image;
  char *uri;
};

G_DEFINE_FINAL_TYPE (BzCuratedArticle, bz_curated_article, G_TYPE_OBJECT);

enum
{
  PROP_0,

  PROP_TITLE,
  PROP_SUBTITLE,
  PROP_IMAGE,
  PROP_URI,

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

static void
bz_curated_article_dispose (GObject *object)
{
  BzCuratedArticle *self = BZ_CURATED_ARTICLE (object);

  g_clear_pointer (&self->title, g_free);
  g_clear_pointer (&self->subtitle, g_free);
  g_clear_pointer (&self->image, g_free);
  g_clear_pointer (&self->uri, g_free);

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

static void
bz_curated_article_get_property (GObject    *object,
                       guint       prop_id,
                       GValue     *value,
                       GParamSpec *pspec)
{
  BzCuratedArticle *self = BZ_CURATED_ARTICLE (object);

  switch (prop_id)
    {
    case PROP_TITLE:
      g_value_set_string (value, bz_curated_article_get_title (self));
      break;
    case PROP_SUBTITLE:
      g_value_set_string (value, bz_curated_article_get_subtitle (self));
      break;
    case PROP_IMAGE:
      g_value_set_string (value, bz_curated_article_get_image (self));
      break;
    case PROP_URI:
      g_value_set_string (value, bz_curated_article_get_uri (self));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}

static void
bz_curated_article_set_property (GObject      *object,
                       guint         prop_id,
                       const GValue *value,
                       GParamSpec   *pspec)
{
  BzCuratedArticle *self = BZ_CURATED_ARTICLE (object);

  switch (prop_id)
    {
    case PROP_TITLE:
      bz_curated_article_set_title (self, g_value_get_string (value));
      break;
    case PROP_SUBTITLE:
      bz_curated_article_set_subtitle (self, g_value_get_string (value));
      break;
    case PROP_IMAGE:
      bz_curated_article_set_image (self, g_value_get_string (value));
      break;
    case PROP_URI:
      bz_curated_article_set_uri (self, g_value_get_string (value));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}

static void
bz_curated_article_class_init (BzCuratedArticleClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);



  object_class->set_property = bz_curated_article_set_property;
  object_class->get_property = bz_curated_article_get_property;
  object_class->dispose      = bz_curated_article_dispose;

  props[PROP_TITLE] =
      g_param_spec_string (
          "title",
          NULL, NULL, NULL,
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);

  props[PROP_SUBTITLE] =
      g_param_spec_string (
          "subtitle",
          NULL, NULL, NULL,
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);

  props[PROP_IMAGE] =
      g_param_spec_string (
          "image",
          NULL, NULL, NULL,
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);

  props[PROP_URI] =
      g_param_spec_string (
          "uri",
          NULL, NULL, NULL,
          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_article_init (BzCuratedArticle *self)
{
}

BzCuratedArticle *
bz_curated_article_new (void){
  return g_object_new (BZ_TYPE_CURATED_ARTICLE, NULL);
}

const char *
bz_curated_article_get_title (BzCuratedArticle *self){
  g_return_val_if_fail (BZ_IS_CURATED_ARTICLE (self), NULL);
  return self->title;
}

const char *
bz_curated_article_get_subtitle (BzCuratedArticle *self){
  g_return_val_if_fail (BZ_IS_CURATED_ARTICLE (self), NULL);
  return self->subtitle;
}

const char *
bz_curated_article_get_image (BzCuratedArticle *self){
  g_return_val_if_fail (BZ_IS_CURATED_ARTICLE (self), NULL);
  return self->image;
}

const char *
bz_curated_article_get_uri (BzCuratedArticle *self){
  g_return_val_if_fail (BZ_IS_CURATED_ARTICLE (self), NULL);
  return self->uri;
}

void
bz_curated_article_set_title (BzCuratedArticle *self,
    const char *title){
  g_return_if_fail (BZ_IS_CURATED_ARTICLE (self));

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

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

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

void
bz_curated_article_set_subtitle (BzCuratedArticle *self,
    const char *subtitle){
  g_return_if_fail (BZ_IS_CURATED_ARTICLE (self));

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

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

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

void
bz_curated_article_set_image (BzCuratedArticle *self,
    const char *image){
  g_return_if_fail (BZ_IS_CURATED_ARTICLE (self));

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

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

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

void
bz_curated_article_set_uri (BzCuratedArticle *self,
    const char *uri){
  g_return_if_fail (BZ_IS_CURATED_ARTICLE (self));

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

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

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

void
bz_curated_article_set_title_take (BzCuratedArticle *self,
    char *title){
  g_return_if_fail (BZ_IS_CURATED_ARTICLE (self));

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

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

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

void
bz_curated_article_set_subtitle_take (BzCuratedArticle *self,
    char *subtitle){
  g_return_if_fail (BZ_IS_CURATED_ARTICLE (self));

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

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

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

void
bz_curated_article_set_image_take (BzCuratedArticle *self,
    char *image){
  g_return_if_fail (BZ_IS_CURATED_ARTICLE (self));

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

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

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

void
bz_curated_article_set_uri_take (BzCuratedArticle *self,
    char *uri){
  g_return_if_fail (BZ_IS_CURATED_ARTICLE (self));

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

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

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

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