-- +goose Up
CREATE TABLE ingredient_mappings (
    id                UUID PRIMARY KEY DEFAULT uuid_generate_v7(),
    canonical_name    VARCHAR(255) NOT NULL,
    canonical_name_ru VARCHAR(255),
    spoonacular_id    INTEGER UNIQUE,

    aliases           JSONB NOT NULL DEFAULT '[]'::jsonb,

    category          VARCHAR(50),
    default_unit      VARCHAR(20),

    -- Nutrients per 100g
    calories_per_100g DECIMAL(8, 2),
    protein_per_100g  DECIMAL(8, 2),
    fat_per_100g      DECIMAL(8, 2),
    carbs_per_100g    DECIMAL(8, 2),
    fiber_per_100g    DECIMAL(8, 2),

    storage_days      INTEGER,

    created_at        TIMESTAMPTZ NOT NULL DEFAULT now(),
    updated_at        TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE INDEX idx_ingredient_mappings_aliases
    ON ingredient_mappings USING GIN (aliases);

CREATE INDEX idx_ingredient_mappings_canonical_name
    ON ingredient_mappings (canonical_name);

CREATE INDEX idx_ingredient_mappings_category
    ON ingredient_mappings (category);

-- +goose Down
DROP TABLE IF EXISTS ingredient_mappings;
