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



struct _BzCuratedArticlesInfo
{
  GObject parent_instance;

  GListModel *list;
  char *uri;
  float aspect_ratio;
};

G_DEFINE_FINAL_TYPE (BzCuratedArticlesInfo, bz_curated_articles_info, G_TYPE_OBJECT);

enum
{
  PROP_0,

  PROP_LIST,
  PROP_URI,
  PROP_ASPECT_RATIO,

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

static void
bz_curated_articles_info_dispose (GObject *object)
{
  BzCuratedArticlesInfo *self = BZ_CURATED_ARTICLES_INFO (object);

  g_clear_pointer (&self->list, g_object_unref);
  g_clear_pointer (&self->uri, g_free);

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

static void
bz_curated_articles_info_get_property (GObject    *object,
                       guint       prop_id,
                       GValue     *value,
                       GParamSpec *pspec)
{
  BzCuratedArticlesInfo *self = BZ_CURATED_ARTICLES_INFO (object);

  switch (prop_id)
    {
    case PROP_LIST:
      g_value_set_object (value, bz_curated_articles_info_get_list (self));
      break;
    case PROP_URI:
      g_value_set_string (value, bz_curated_articles_info_get_uri (self));
      break;
    case PROP_ASPECT_RATIO:
      g_value_set_float (value, bz_curated_articles_info_get_aspect_ratio (self));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}

static void
bz_curated_articles_info_set_property (GObject      *object,
                       guint         prop_id,
                       const GValue *value,
                       GParamSpec   *pspec)
{
  BzCuratedArticlesInfo *self = BZ_CURATED_ARTICLES_INFO (object);

  switch (prop_id)
    {
    case PROP_LIST:
      bz_curated_articles_info_set_list (self, g_value_get_object (value));
      break;
    case PROP_URI:
      bz_curated_articles_info_set_uri (self, g_value_get_string (value));
      break;
    case PROP_ASPECT_RATIO:
      bz_curated_articles_info_set_aspect_ratio (self, g_value_get_float (value));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}

static void
bz_curated_articles_info_class_init (BzCuratedArticlesInfoClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);



  object_class->set_property = bz_curated_articles_info_set_property;
  object_class->get_property = bz_curated_articles_info_get_property;
  object_class->dispose      = bz_curated_articles_info_dispose;

  props[PROP_LIST] =
      g_param_spec_object (
          "list",
          NULL, NULL,
          G_TYPE_LIST_MODEL,
          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);

  props[PROP_ASPECT_RATIO] =
      g_param_spec_float (
          "aspect-ratio",
          NULL, NULL,
          G_MININT, G_MAXINT, 0.0,
          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_articles_info_init (BzCuratedArticlesInfo *self)
{
}

BzCuratedArticlesInfo *
bz_curated_articles_info_new (void){
  return g_object_new (BZ_TYPE_CURATED_ARTICLES_INFO, NULL);
}

GListModel *
bz_curated_articles_info_get_list (BzCuratedArticlesInfo *self){
  g_return_val_if_fail (BZ_IS_CURATED_ARTICLES_INFO (self), NULL);
  return self->list;
}

const char *
bz_curated_articles_info_get_uri (BzCuratedArticlesInfo *self){
  g_return_val_if_fail (BZ_IS_CURATED_ARTICLES_INFO (self), NULL);
  return self->uri;
}

float
bz_curated_articles_info_get_aspect_ratio (BzCuratedArticlesInfo *self){
  g_return_val_if_fail (BZ_IS_CURATED_ARTICLES_INFO (self), 0.0);
  return self->aspect_ratio;
}

void
bz_curated_articles_info_set_list (BzCuratedArticlesInfo *self,
    GListModel *list){
  g_return_if_fail (BZ_IS_CURATED_ARTICLES_INFO (self));

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

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

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

void
bz_curated_articles_info_set_uri (BzCuratedArticlesInfo *self,
    const char *uri){
  g_return_if_fail (BZ_IS_CURATED_ARTICLES_INFO (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_articles_info_set_aspect_ratio (BzCuratedArticlesInfo *self,
    float aspect_ratio){
  g_return_if_fail (BZ_IS_CURATED_ARTICLES_INFO (self));

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

  self->aspect_ratio = aspect_ratio;

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

void
bz_curated_articles_info_set_uri_take (BzCuratedArticlesInfo *self,
    char *uri){
  g_return_if_fail (BZ_IS_CURATED_ARTICLES_INFO (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-articles-info.c */
