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



struct _BzLinearFunction
{
  GObject parent_instance;

  double slope;
  double y_intercept;
};

G_DEFINE_FINAL_TYPE (BzLinearFunction, bz_linear_function, G_TYPE_OBJECT);

enum
{
  PROP_0,

  PROP_SLOPE,
  PROP_Y_INTERCEPT,

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

static void
bz_linear_function_dispose (GObject *object)
{
  BzLinearFunction *self = BZ_LINEAR_FUNCTION (object);



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

static void
bz_linear_function_get_property (GObject    *object,
                       guint       prop_id,
                       GValue     *value,
                       GParamSpec *pspec)
{
  BzLinearFunction *self = BZ_LINEAR_FUNCTION (object);

  switch (prop_id)
    {
    case PROP_SLOPE:
      g_value_set_double (value, bz_linear_function_get_slope (self));
      break;
    case PROP_Y_INTERCEPT:
      g_value_set_double (value, bz_linear_function_get_y_intercept (self));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}

static void
bz_linear_function_set_property (GObject      *object,
                       guint         prop_id,
                       const GValue *value,
                       GParamSpec   *pspec)
{
  BzLinearFunction *self = BZ_LINEAR_FUNCTION (object);

  switch (prop_id)
    {
    case PROP_SLOPE:
      bz_linear_function_set_slope (self, g_value_get_double (value));
      break;
    case PROP_Y_INTERCEPT:
      bz_linear_function_set_y_intercept (self, g_value_get_double (value));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}

static void
bz_linear_function_class_init (BzLinearFunctionClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);



  object_class->set_property = bz_linear_function_set_property;
  object_class->get_property = bz_linear_function_get_property;
  object_class->dispose      = bz_linear_function_dispose;

  props[PROP_SLOPE] =
      g_param_spec_double (
          "slope",
          NULL, NULL,
          G_MININT, G_MAXINT, 0.0,
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);

  props[PROP_Y_INTERCEPT] =
      g_param_spec_double (
          "y-intercept",
          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_linear_function_init (BzLinearFunction *self)
{
}

BzLinearFunction *
bz_linear_function_new (void){
  return g_object_new (BZ_TYPE_LINEAR_FUNCTION, NULL);
}

double
bz_linear_function_get_slope (BzLinearFunction *self){
  g_return_val_if_fail (BZ_IS_LINEAR_FUNCTION (self), 0.0);
  return self->slope;
}

double
bz_linear_function_get_y_intercept (BzLinearFunction *self){
  g_return_val_if_fail (BZ_IS_LINEAR_FUNCTION (self), 0.0);
  return self->y_intercept;
}

void
bz_linear_function_set_slope (BzLinearFunction *self,
    double slope){
  g_return_if_fail (BZ_IS_LINEAR_FUNCTION (self));

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

  self->slope = slope;

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

void
bz_linear_function_set_y_intercept (BzLinearFunction *self,
    double y_intercept){
  g_return_if_fail (BZ_IS_LINEAR_FUNCTION (self));

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

  self->y_intercept = y_intercept;

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



/* End of src/bazaar.p/bz-linear-function.c */
