#ifndef _GRAPH_H
#define _GRAPH_H

#include "naive_ppm.h"
#include <stddef.h>

#define NULL_NODE ((size_t)-1)

typedef struct _arc {
    size_t target;
    int capacity;
    int flow;
    struct _arc* opposite;
} arc;

typedef struct {
    size_t
        nb_nodes;   // number of nodes in the graph, including source and sink
    size_t source;  // index of source
    size_t sink;    // index of sink
    size_t* degree; // degree[v] gives the degree of node v
    arc** Adj;      // Adj[v] is the array of neighboors of v, of // length
               // degre[v] This array ends with an extra dummy arc with target
               // == NULL_NODE

    size_t _width;
    size_t _height;
    arc* _arcs; // all inner arcs
    arc* _source_arcs;
    size_t _nb_source_arcs;
    arc* _sink_arcs;
    size_t _nb_sink_arcs;
    char* _label;
} graph;

void free_graph(graph* G);

graph* image_to_graph(PPM* img, PPM* hard_seeds, PPM* soft_seeds,
    double sigma, double lambda, int coeff, int nb_neighboors, int opt);

// in maxflow-*.c file
arc* get_arc(graph* G, size_t from, size_t to);

int apply_mask_PPM(PPM* img, graph* G, const char mask[],
    const char* output_filename, color_mode obj_mode, color_mode bg_mode,
    color_mode boundary_mode, int boundary_width);
#endif
