include .env
.PHONY: test
test:
	@docker compose up -d test
	@docker compose exec test go test ./...
	@docker compose stop test

.PHONY: coverage
coverage:
	@mkdir -p coverage
	@docker compose up -d test
	@docker compose exec test sh -c "go test -coverprofile=coverage.out ./internal/... && go tool cover -func=coverage.out -o coverage/coverage.txt"
	@docker cp $(shell docker ps -q -f "name=fortunebet-test-1"):/app/coverage ./ || true
	@docker compose stop test

.PHONY: build
build:
	@docker compose build app

.PHONY: run
run:
	@docker compose up

.PHONY: stop
stop:
	@docker compose down

.PHONY: air
air:
	@echo "Running air locally (not in Docker)"
	@air -c .air.toml
.PHONY: migrations/up
migrations/new:
	@echo 'Creating migration files for DB_URL'
	@migrate create -seq -ext=.sql -dir=./db/migrations $(name)

.PHONY: migrations/up
migrations/up:
	@echo 'Running up migrations...'
	@docker compose up migrate

.PHONY: postgres 
postgres:
	@echo 'Running postgres db...'
	docker compose -f docker-compose.yml exec postgres psql -U root -d gh

.PHONY: swagger
swagger:
	@swag init -g cmd/main.go

.PHONY: db-up
db-up:
	@docker compose up -d postgres migrate mongo

.PHONY: db-down
db-down:
	@docker compose down
	@docker volume rm fortunebet-backend_postgres_data
.PHONY: sqlc-gen
sqlc-gen:
	@sqlc generate