create or replace function ems.fn_planning_future_price_days()
returns int
language sql
stable
as $fn$
  select count(distinct (mip.interval_start at time zone 'Europe/Prague')::date)::int
  from ems.market_interval_price mip
  where mip.market_source in ('OTE_CZ', 'OTE_CZ_DAM')
    and mip.interval_start >= now()
    and mip.interval_start < now() + interval '48 hours';
$fn$;

comment on function ems.fn_planning_future_price_days() is
  'Počet kalendářních dní s OTE daty v okně now..now+48h (před spuštěním plánu).';
