-- Unit dictionary seed. Keep factors aligned with ingestion/opengoods/units.py.

INSERT INTO unit (code, dimension, canonical, to_canonical_factor, aliases, display) VALUES
    ('mg',   'mass',     'g',   0.001,  ARRAY['毫克'],                 'mg'),
    ('g',    'mass',     'g',   1,      ARRAY['克','gram','grams'],    'g'),
    ('kg',   'mass',     'g',   1000,   ARRAY['kgs','千克','公斤'],     'kg'),
    ('ml',   'volume',   'ml',  1,      ARRAY['毫升','milliliter'],     'mL'),
    ('cl',   'volume',   'ml',  10,     ARRAY['厘升'],                 'cL'),
    ('l',    'volume',   'ml',  1000,   ARRAY['L','升','litre','liter'], 'L'),
    ('kj',   'energy',   'kJ',  1,      ARRAY['kJ','千焦'],            'kJ'),
    ('kcal', 'energy',   'kJ',  4.184,  ARRAY['千卡','大卡'],          'kcal'),
    ('pct',  'ratio',    'pct', 1,      ARRAY['%','percent','百分比'],  '%'),
    ('unit', 'count',    'unit',1,      ARRAY['个','件','pcs','piece'], '个'),
    ('mm',   'length',   'mm',  1,      ARRAY['毫米'],                 'mm'),
    ('cm',   'length',   'mm',  10,     ARRAY['厘米'],                 'cm'),
    ('day',  'duration', 'day', 1,      ARRAY['天','日','days'],        'day')
ON CONFLICT (code) DO NOTHING;

-- A few common food attribute definitions referencing the unit dictionary.
INSERT INTO attribute_definition (key, label_zh, label_en, dimension, default_unit, aliases) VALUES
    ('energy',        '能量',   'Energy',        'energy', 'kj',   ARRAY['energy_kj']),
    ('proteins',      '蛋白质', 'Proteins',      'mass',   'g',    ARRAY['protein']),
    ('fat',           '脂肪',   'Fat',           'mass',   'g',    ARRAY['fats']),
    ('saturated_fat', '饱和脂肪','Saturated fat','mass',   'g',    ARRAY['saturated-fat']),
    ('carbohydrates', '碳水化合物','Carbohydrates','mass', 'g',    ARRAY['carbs']),
    ('sugars',        '糖',     'Sugars',        'mass',   'g',    ARRAY['sugar']),
    ('salt',          '盐',     'Salt',          'mass',   'g',    ARRAY['sodium_salt']),
    ('net_content',   '净含量', 'Net content',   NULL,     NULL,   ARRAY['quantity'])
ON CONFLICT (key) DO NOTHING;
