#!/usr/bin/env bash
# Copyright 2022 Cisco Systems, Inc. and its affiliates
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0


GEN_DIR=./openapi
PKG_DIR=../pkg/openapi

IGNORE_FILES=()
# IGNORE_FILES=(api_computes_service.go \
# 		  api_datasets_service.go \
# 		  api_design_codes_service.go \
# 		  api_design_schemas_service.go \
# 		  api_designs_service.go \
# 		  api_jobs_service.go)

FILES_IN_GEN_DIR=`ls -F $GEN_DIR`
FILES_IN_PKG_DIR=`ls -F $PKG_DIR`

COMM_FILES=`comm -12 <(ls -F $GEN_DIR) <(ls -F $PKG_DIR)`

NEW_FILES=`comm -23 \
        <(printf '%s\n' "${FILES_IN_GEN_DIR[@]}" | sort) \
        <(printf '%s\n' "${COMM_FILES[@]}" | sort)`

MISSING_FILES=`comm -23 \
        <(printf '%s\n' "${FILES_IN_PKG_DIR[@]}" | sort) \
        <(printf '%s\n' "${COMM_FILES[@]}" | sort)`

echo "This script is to help development of openapi related features."
echo "It prints out directory content difference" \
     "between flame/scripts/openapi and flame/pkg/openapi."
echo "Note that flame/scripts/openapi is auto-generated by openapi.sh."
echo

echo "New file(s) (files in flame/scripts/openapi but not in flame/pkg/openapi):"
for filename in ${NEW_FILES[@]}; do
    if [[ "${IGNORE_FILES[*]}" =~ "${filename}" ]]; then
	continue
    fi
    echo "    "$filename
    done

echo "Missing file(s) (files in flame/pkg/openapi but not in flame/scripts/openapi):"
for filename in ${MISSING_FILES[@]}; do
    if [[ "${IGNORE_FILES[*]}" =~ "${filename}" ]]; then
	continue
    fi
    echo "    "$filename
done
