--
-- news__status/2
--
create or replace function news__status(
  timestamp with time zone,
  timestamp with time zone
) returns varchar as $$

declare
    p_publish_date alias for $1;
    p_archive_date alias for $2;
begin
    if p_publish_date is not null then
        if p_publish_date > current_timestamp then
            -- Publishing in the future
            if p_archive_date is null then 
                return 'going_live_no_archive';
            else 
                return 'going_live_with_archive';
            end if;  
        else
            -- Published in the past
            if p_archive_date is null then
                 return 'published_no_archive';
            else
                if p_archive_date > current_timestamp then
                     return 'published_with_archive';
                else 
                    return 'archived';
                end if;
            end if;
        end if;
    else
        -- publish_date null
        return 'unapproved';
    end if;
end;
$$ language plpgsql;