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and address is null and address2 is null and city is null and postal_code is null and longitude is null and latitude is null and osrm_hint is null and timezone is null) or
(type = 'physical' and address is not null and city is not null and postal_code is not null and longitude is not null and latitude is not null and timezone is not null)
)
partner boolean not null default true,
delivery boolean not null default true,
pickup boolean not null default true,
prepayment boolean not null default true--right now, this means the dumb af "give me credit card number" over phone, or etransfer, but eventually will be moneris
create or replace function ios_store_id(_name text, _url text, _region citext, _country citext, out _store_id integer) as $$
create or replace function ios_store_id(
_name text,
_region citext,
_country citext,
_address citext = null,
_address2 citext = null,
_city citext = null,
_postal_code citext = null,
_url text = null,
_longitude decimal = null,
_latitude decimal = null,
_osrm_hint_foot text = null,
_osrm_hint_car text = null,
_timezone text = null,
_phone packed_phone_number = null,
_partner boolean = false,
_delivery boolean = false,
_pickup boolean = false,
_prepayment boolean = false,
out _store_id integer
) as $$
create or replace function get_store(_store_id integer) returns table(name text, url text, address citext, address2 citext, city citext, region citext, country citext, postal_code citext, longitude decimal, latitude decimal, timezone text, images json, times json, physical boolean) as $$
create or replace function get_store(_store_id integer) returns table(name text, url text, address text, images json, times json, timezone text, phone packed_phone_number, partner boolean, delivery boolean, pickup boolean, prepayment boolean) as $$
'store', json_build_object(
--distance
--closed or open. if closed, when is it opening next?
'id', store_id,
'name', s.name,
'image', (select store_image.url from store_image where store_image.store_id = s.store_id limit 1)--order by rank someday
),
'store', store_id,
'default_concentrations', (select json_agg(json_build_object('name', store.name, 'min_thc', lower(thc), 'max_thc', upper(thc), 'min_cbd',lower(cbd), 'max_cbd', upper(cbd))) from menu_item inner join store using (store_id) where store.type = 'online' and variant_id = v.variant_id)
'default_concentrations', (select json_agg(json_build_object('name', store.name, 'min_thc', lower(thc), 'max_thc', upper(thc), 'min_cbd',lower(cbd), 'max_cbd', upper(cbd))) from menu_item inner join store using (store_id) where not store.partner and variant_id = v.variant_id)
let storeID = (await postgres.query(`select ios_store_id('Ontario Cannabis Store', $1, 'ontario', 'canada')`, [url])).rows[0].ios_store_id;
let storeID = (await postgres.query(`select ios_store_id('Ontario Cannabis Store', 'ontario', 'canada', _url => $1, _delivery => true, _prepayment => true)`, [url])).rows[0].ios_store_id;