:: SPDX-License-Identifier: Apache-2.0
@echo off
setlocal

REM Where to generate the certificates
IF "%~1"=="" (
  set "TARGET_DIR=buildtools\certs"
) ELSE (
  set "TARGET_DIR=%~1"
)

REM Create directories
if not exist "%TARGET_DIR%" mkdir "%TARGET_DIR%"
pushd "%TARGET_DIR%"

REM Generate certificates
CALL npx -y mkcert create-ca --organization GeoGirafe --key rootCA-key.pem --cert rootCA.pem
CALL npx -y mkcert create-cert --ca-key rootCA-key.pem --ca-cert rootCA.pem --key app.localhost.key.pem --cert app.localhost.cert.pem --domains app.localhost localhost 127.0.0.1
echo Certificate was created successfully.

REM Add root certificate to trusted store (for the current user)
certutil -user -addstore root "rootCA.pem"
echo Certificate was added successfully.
echo Please restart your browser to take it into account.

popd
