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



struct _BzCuratedBanner
{
  GObject parent_instance;

  BzCuratedImageInfo *image;
  char *light_color;
  char *dark_color;
  int height;
};

G_DEFINE_FINAL_TYPE (BzCuratedBanner, bz_curated_banner, G_TYPE_OBJECT);

enum
{
  PROP_0,

  PROP_IMAGE,
  PROP_LIGHT_COLOR,
  PROP_DARK_COLOR,
  PROP_HEIGHT,

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

static void
bz_curated_banner_dispose (GObject *object)
{
  BzCuratedBanner *self = BZ_CURATED_BANNER (object);

  g_clear_pointer (&self->image, g_object_unref);
  g_clear_pointer (&self->light_color, g_free);
  g_clear_pointer (&self->dark_color, g_free);

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

static void
bz_curated_banner_get_property (GObject    *object,
                       guint       prop_id,
                       GValue     *value,
                       GParamSpec *pspec)
{
  BzCuratedBanner *self = BZ_CURATED_BANNER (object);

  switch (prop_id)
    {
    case PROP_IMAGE:
      g_value_set_object (value, bz_curated_banner_get_image (self));
      break;
    case PROP_LIGHT_COLOR:
      g_value_set_string (value, bz_curated_banner_get_light_color (self));
      break;
    case PROP_DARK_COLOR:
      g_value_set_string (value, bz_curated_banner_get_dark_color (self));
      break;
    case PROP_HEIGHT:
      g_value_set_int (value, bz_curated_banner_get_height (self));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}

static void
bz_curated_banner_set_property (GObject      *object,
                       guint         prop_id,
                       const GValue *value,
                       GParamSpec   *pspec)
{
  BzCuratedBanner *self = BZ_CURATED_BANNER (object);

  switch (prop_id)
    {
    case PROP_IMAGE:
      bz_curated_banner_set_image (self, g_value_get_object (value));
      break;
    case PROP_LIGHT_COLOR:
      bz_curated_banner_set_light_color (self, g_value_get_string (value));
      break;
    case PROP_DARK_COLOR:
      bz_curated_banner_set_dark_color (self, g_value_get_string (value));
      break;
    case PROP_HEIGHT:
      bz_curated_banner_set_height (self, g_value_get_int (value));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}

static void
bz_curated_banner_class_init (BzCuratedBannerClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);



  object_class->set_property = bz_curated_banner_set_property;
  object_class->get_property = bz_curated_banner_get_property;
  object_class->dispose      = bz_curated_banner_dispose;

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

  props[PROP_LIGHT_COLOR] =
      g_param_spec_string (
          "light-color",
          NULL, NULL, NULL,
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);

  props[PROP_DARK_COLOR] =
      g_param_spec_string (
          "dark-color",
          NULL, NULL, NULL,
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);

  props[PROP_HEIGHT] =
      g_param_spec_int (
          "height",
          NULL, NULL,
          G_MININT, G_MAXINT, 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_banner_init (BzCuratedBanner *self)
{
}

BzCuratedBanner *
bz_curated_banner_new (void){
  return g_object_new (BZ_TYPE_CURATED_BANNER, NULL);
}

BzCuratedImageInfo *
bz_curated_banner_get_image (BzCuratedBanner *self){
  g_return_val_if_fail (BZ_IS_CURATED_BANNER (self), NULL);
  return self->image;
}

const char *
bz_curated_banner_get_light_color (BzCuratedBanner *self){
  g_return_val_if_fail (BZ_IS_CURATED_BANNER (self), NULL);
  return self->light_color;
}

const char *
bz_curated_banner_get_dark_color (BzCuratedBanner *self){
  g_return_val_if_fail (BZ_IS_CURATED_BANNER (self), NULL);
  return self->dark_color;
}

int
bz_curated_banner_get_height (BzCuratedBanner *self){
  g_return_val_if_fail (BZ_IS_CURATED_BANNER (self), 0);
  return self->height;
}

void
bz_curated_banner_set_image (BzCuratedBanner *self,
    BzCuratedImageInfo *image){
  g_return_if_fail (BZ_IS_CURATED_BANNER (self));

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

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

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

void
bz_curated_banner_set_light_color (BzCuratedBanner *self,
    const char *light_color){
  g_return_if_fail (BZ_IS_CURATED_BANNER (self));

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

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

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

void
bz_curated_banner_set_dark_color (BzCuratedBanner *self,
    const char *dark_color){
  g_return_if_fail (BZ_IS_CURATED_BANNER (self));

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

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

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

void
bz_curated_banner_set_height (BzCuratedBanner *self,
    int height){
  g_return_if_fail (BZ_IS_CURATED_BANNER (self));

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

  self->height = height;

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

void
bz_curated_banner_set_light_color_take (BzCuratedBanner *self,
    char *light_color){
  g_return_if_fail (BZ_IS_CURATED_BANNER (self));

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

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

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

void
bz_curated_banner_set_dark_color_take (BzCuratedBanner *self,
    char *dark_color){
  g_return_if_fail (BZ_IS_CURATED_BANNER (self));

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

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

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

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