.PHONY: build

fresh:
	$(MAKE) stop && \
	rm -rf ./src && \
	./scripts/download_oc_store.sh && \
	./scripts/install_ocstore.sh && \
	$(MAKE) start

setup:
	$(MAKE) stop && \
	rm -rf ./src && \
	./scripts/download_oc_store.sh && \
	./scripts/install_ocstore.sh && \
	$(MAKE) start && \
	$(MAKE) link

stop:
	docker compose down

start:
	docker compose up -d

restart:
	docker compose down && docker compose up -d

ssh:
	docker compose exec -w /module/oc_telegram_shop/upload/oc_telegram_shop web bash

link:
	docker compose exec web bash -c "php ./scripts/link.php"

dev:
	$(MAKE) link
	@echo "Starting SPA + Admin..."
	@make -j2 dev-spa dev-admin

dev-spa:
	rm -rf module/oc_telegram_shop/upload/system/library/oc_telegram_shop && \
	cd frontend/spa && npm run dev

dev-admin:
	rm -rf module/oc_telegram_shop/upload/admin/view/javascript && \
	rm -rf module/oc_telegram_shop/upload/system/library/oc_telegram_shop && \
	rm -rf src/upload/admin/view/javascript/telecart && \
	cd frontend/admin && npm run dev

ocmod:
	./scripts/apply_ocmod.sh

lint:
	docker compose exec -w /module/oc_telegram_shop/upload/oc_telegram_shop web bash -c "./vendor/bin/phpstan analyse"

phpcs:
	docker compose exec -w /module/oc_telegram_shop/upload/oc_telegram_shop web bash -c "./vendor/bin/phpcs --standard=PSR12 bastion framework src"

phpcbf:
	docker compose exec -w /module/oc_telegram_shop/upload/oc_telegram_shop web bash -c "./vendor/bin/phpcbf --standard=PSR12 bastion framework src"

test:
	docker compose exec -w /module/oc_telegram_shop/upload/oc_telegram_shop web bash -c "./vendor/bin/phpunit --testdox tests/"

test-integration:
	docker compose exec -w /module/oc_telegram_shop/upload/oc_telegram_shop web bash -c "./vendor/bin/phpunit --testdox tests/Integration"

test-unit:
	docker compose exec -w /module/oc_telegram_shop/upload/oc_telegram_shop web bash -c "./vendor/bin/phpunit --testdox tests/Unit"

test-telegram:
	docker compose exec -w /module/oc_telegram_shop/upload/oc_telegram_shop web bash -c "./vendor/bin/phpunit --testdox tests/Telegram"

test-coverage:
	docker compose exec -w /module/oc_telegram_shop/upload/oc_telegram_shop web bash -c "./vendor/bin/phpunit --coverage-html coverage tests/"

phar:
	docker build -t telecart_local_build -f ./docker/build.dockerfile . && \
	docker run -v "./src/upload/system/library/oc_telegram_shop:/build" telecart_local_build sh -c 'sh /scripts/build_phar.sh'

cli:
	docker compose exec -w /module/oc_telegram_shop/upload web bash -c "/usr/local/bin/php cli.php $(ARGS)"

changelog:
	php ./module/oc_telegram_shop/upload/oc_telegram_shop/vendor/bin/conventional-changelog

release:
	php ./module/oc_telegram_shop/upload/oc_telegram_shop/vendor/bin/conventional-changelog --commit