#!/usr/bin/env bash
# Script para criar a estrutura completa do Projeto Integrador
# Uso: execute este script na raiz do repositorio do seu projeto

set -e

echo "Criando estrutura do Projeto Integrador..."

# ============================================================
# RAIZ
# ============================================================
touch README.md
touch .gitignore

# Assets
mkdir -p frontend/assets/images
mkdir -p frontend/assets/fonts
mkdir -p frontend/assets/i18n
touch frontend/assets/i18n/strings_pt.i18n.dart
touch frontend/assets/i18n/strings_en.i18n.dart

# Integration test
mkdir -p frontend/integration_test
touch frontend/integration_test/app_test.dart

# Tests
mkdir -p frontend/test/features/auth/domain/entities
mkdir -p frontend/test/features/auth/domain/usecases
mkdir -p frontend/test/features/auth/presentation/providers
mkdir -p frontend/test/helpers
touch frontend/test/features/auth/domain/entities/user_test.dart
touch frontend/test/features/auth/domain/usecases/sign_in_usecase_test.dart
touch frontend/test/features/auth/presentation/providers/auth_provider_test.dart
touch frontend/test/helpers/test_helpers.dart

# lib/app
mkdir -p frontend/lib/app
touch frontend/lib/main.dart
touch frontend/lib/app/app_widget.dart
touch frontend/lib/app/app_router.dart
touch frontend/lib/app/app_theme.dart
touch frontend/lib/app/app_providers.dart

# lib/core/di
mkdir -p frontend/lib/core/di
touch frontend/lib/core/di/injection_container.dart

# lib/core/error
mkdir -p frontend/lib/core/error
touch frontend/lib/core/error/failures.dart
touch frontend/lib/core/error/exceptions.dart

# lib/core/network
mkdir -p frontend/lib/core/network
touch frontend/lib/core/network/http_client.dart
touch frontend/lib/core/network/auth_interceptor.dart

# lib/core/storage
mkdir -p frontend/lib/core/storage
touch frontend/lib/core/storage/secure_storage_service.dart
touch frontend/lib/core/storage/preferences_service.dart

# lib/core/utils/extensions
mkdir -p frontend/lib/core/utils/extensions
touch frontend/lib/core/utils/date_formatter.dart
touch frontend/lib/core/utils/validators.dart
touch frontend/lib/core/utils/extensions/string_extensions.dart
touch frontend/lib/core/utils/extensions/context_extensions.dart

# lib/core/widgets
mkdir -p frontend/lib/core/widgets
touch frontend/lib/core/widgets/app_button.dart
touch frontend/lib/core/widgets/app_text_field.dart
touch frontend/lib/core/widgets/loading_overlay_widget.dart
touch frontend/lib/core/widgets/error_widget.dart
touch frontend/lib/core/widgets/empty_state_widget.dart

# lib/core/theme
mkdir -p frontend/lib/core/theme
touch frontend/lib/core/theme/app_colors.dart
touch frontend/lib/core/theme/app_typography.dart
touch frontend/lib/core/theme/app_spacing.dart

# features/auth
mkdir -p frontend/lib/features/auth/domain/entities
mkdir -p frontend/lib/features/auth/domain/value_objects
mkdir -p frontend/lib/features/auth/domain/repositories
mkdir -p frontend/lib/features/auth/domain/usecases
mkdir -p frontend/lib/features/auth/infrastructure/repositories
mkdir -p frontend/lib/features/auth/infrastructure/datasources
mkdir -p frontend/lib/features/auth/infrastructure/dtos
mkdir -p frontend/lib/features/auth/presentation/providers
mkdir -p frontend/lib/features/auth/presentation/pages
mkdir -p frontend/lib/features/auth/presentation/widgets
touch frontend/lib/features/auth/domain/entities/user.dart
touch frontend/lib/features/auth/domain/value_objects/email.dart
touch frontend/lib/features/auth/domain/repositories/i_auth_repository.dart
touch frontend/lib/features/auth/domain/usecases/sign_in_usecase.dart
touch frontend/lib/features/auth/domain/usecases/sign_out_usecase.dart
touch frontend/lib/features/auth/infrastructure/repositories/auth_repository.dart
touch frontend/lib/features/auth/infrastructure/datasources/auth_remote_datasource.dart
touch frontend/lib/features/auth/infrastructure/datasources/auth_local_datasource.dart
touch frontend/lib/features/auth/infrastructure/dtos/user_dto.dart
touch frontend/lib/features/auth/presentation/providers/auth_provider.dart
touch frontend/lib/features/auth/presentation/pages/login_page.dart
touch frontend/lib/features/auth/presentation/pages/splash_page.dart
touch frontend/lib/features/auth/presentation/widgets/login_form.dart

# features/home
mkdir -p frontend/lib/features/home/domain/usecases
mkdir -p frontend/lib/features/home/infrastructure
mkdir -p frontend/lib/features/home/presentation/providers
mkdir -p frontend/lib/features/home/presentation/pages
mkdir -p frontend/lib/features/home/presentation/widgets
touch frontend/lib/features/home/domain/usecases/get_summary_usecase.dart
touch frontend/lib/features/home/presentation/providers/home_provider.dart
touch frontend/lib/features/home/presentation/pages/home_page.dart
touch frontend/lib/features/home/presentation/widgets/summary_card.dart
touch frontend/lib/features/home/presentation/widgets/recent_items_list.dart

# features/notifications
mkdir -p frontend/lib/features/notifications/domain/entities
mkdir -p frontend/lib/features/notifications/domain/usecases
mkdir -p frontend/lib/features/notifications/infrastructure/services
mkdir -p frontend/lib/features/notifications/presentation/providers
touch frontend/lib/features/notifications/domain/entities/push_notification.dart
touch frontend/lib/features/notifications/domain/usecases/handle_notification_usecase.dart
touch frontend/lib/features/notifications/infrastructure/services/fcm_service.dart
touch frontend/lib/features/notifications/presentation/providers/notification_provider.dart

# features/native_resources
mkdir -p frontend/lib/features/native_resources/domain/usecases
mkdir -p frontend/lib/features/native_resources/infrastructure/services
mkdir -p frontend/lib/features/native_resources/presentation/widgets
touch frontend/lib/features/native_resources/domain/usecases/capture_photo_usecase.dart
touch frontend/lib/features/native_resources/domain/usecases/get_location_usecase.dart
touch frontend/lib/features/native_resources/infrastructure/services/camera_service.dart
touch frontend/lib/features/native_resources/infrastructure/services/location_service.dart
touch frontend/lib/features/native_resources/presentation/widgets/camera_capture_widget.dart
touch frontend/lib/features/native_resources/presentation/widgets/location_picker_widget.dart

# features/settings
mkdir -p frontend/lib/features/settings/domain/entities
mkdir -p frontend/lib/features/settings/domain/usecases
mkdir -p frontend/lib/features/settings/infrastructure/repositories
mkdir -p frontend/lib/features/settings/presentation/providers
mkdir -p frontend/lib/features/settings/presentation/pages
touch frontend/lib/features/settings/domain/entities/user_settings.dart
touch frontend/lib/features/settings/domain/usecases/change_language_usecase.dart
touch frontend/lib/features/settings/infrastructure/repositories/settings_repository.dart
touch frontend/lib/features/settings/presentation/providers/settings_provider.dart
touch frontend/lib/features/settings/presentation/pages/settings_page.dart

# features/profile
mkdir -p frontend/lib/features/profile/domain/usecases
mkdir -p frontend/lib/features/profile/infrastructure
mkdir -p frontend/lib/features/profile/presentation/providers
mkdir -p frontend/lib/features/profile/presentation/pages
touch frontend/lib/features/profile/domain/usecases/get_user_profile_usecase.dart
touch frontend/lib/features/profile/presentation/providers/profile_provider.dart
touch frontend/lib/features/profile/presentation/pages/profile_page.dart

# ============================================================
# BACKEND
# ============================================================
mkdir -p backend
touch backend/README.md
touch backend/requirements.txt
touch backend/.env.example

# backend/shared
mkdir -p backend/shared/database
mkdir -p backend/shared/auth
mkdir -p backend/shared/models
mkdir -p backend/shared/utils
touch backend/shared/database/connection.py
touch backend/shared/auth/token_verifier.py
touch backend/shared/models/base_model.py
touch backend/shared/utils/response_builder.py
touch backend/shared/utils/validators.py

# backend/database
mkdir -p backend/database/migrations
touch backend/database/schema.sql
touch backend/database/seed.sql
touch backend/database/migrations/001_initial_schema.sql
touch backend/database/migrations/002_add_notifications_table.sql

# backend/infrastructure
mkdir -p backend/infrastructure/iam_policies
touch backend/infrastructure/api_gateway_config.json
touch backend/infrastructure/sqs_config.json
touch backend/infrastructure/iam_policies/lambda_execution_policy.json
touch backend/infrastructure/iam_policies/rds_access_policy.json

# backend/tests
mkdir -p backend/tests/unit/auth
mkdir -p backend/tests/integration
mkdir -p backend/tests/fixtures
touch backend/tests/unit/auth/test_sign_in.py
touch backend/tests/integration/test_database_operations.py
touch backend/tests/fixtures/sample_data.json

# backend/lambdas/auth
mkdir -p backend/lambdas/auth/domain
mkdir -p backend/lambdas/auth/infrastructure
touch backend/lambdas/auth/handler.py
touch backend/lambdas/auth/domain/entities.py
touch backend/lambdas/auth/domain/usecases.py
touch backend/lambdas/auth/infrastructure/user_repository.py
touch backend/lambdas/auth/infrastructure/token_service.py
touch backend/lambdas/auth/requirements.txt

# backend/lambdas/notifications
mkdir -p backend/lambdas/notifications/domain
mkdir -p backend/lambdas/notifications/infrastructure
touch backend/lambdas/notifications/handler.py
touch backend/lambdas/notifications/domain/usecases.py
touch backend/lambdas/notifications/infrastructure/fcm_service.py
touch backend/lambdas/notifications/requirements.txt

# ============================================================
# INTEGRACAO
# ============================================================
touch integracao/README.md

# integracao/contracts
mkdir -p integracao/contracts/examples
touch integracao/contracts/api-contract.md
touch integracao/contracts/openapi.yaml
touch integracao/contracts/examples/auth_request.json
touch integracao/contracts/examples/auth_response.json
touch integracao/contracts/examples/error_response.json

# integracao/mocks
mkdir -p integracao/mocks
touch integracao/mocks/mock_server.py
touch integracao/mocks/mock_data.json

# integracao/e2e_tests
mkdir -p integracao/e2e_tests
touch integracao/e2e_tests/test_auth_flow.py

# ============================================================
# DOC
# ============================================================
mkdir -p doc
touch doc/README.md

# doc/diario
mkdir -p doc/diario
touch doc/diario/template_diario.md
touch doc/diario/modulo_01.md
touch doc/diario/modulo_02.md
touch doc/diario/modulo_03.md
touch doc/diario/modulo_04.md
touch doc/diario/modulo_05.md
touch doc/diario/modulo_06.md
touch doc/diario/modulo_07.md
touch doc/diario/modulo_08.md
touch doc/diario/modulo_09.md
touch doc/diario/modulo_10.md
touch doc/diario/modulo_11.md
touch doc/diario/modulo_12.md
touch doc/diario/modulo_13.md
touch doc/diario/modulo_14.md
touch doc/diario/modulo_15.md

# doc/arquitetura
mkdir -p doc/arquitetura
touch doc/arquitetura/visao_geral.md
touch doc/arquitetura/diagrama_componentes.md
touch doc/arquitetura/diagrama_sequencia_auth.md
touch doc/arquitetura/diagrama_sequencia_notificacao.md
touch doc/arquitetura/diagrama_er.md

# doc/decisoes
mkdir -p doc/decisoes
touch doc/decisoes/001_escolha_gerenciamento_estado.md
touch doc/decisoes/002_organizacao_feature_first.md

# doc/prototipo
mkdir -p doc/prototipo/wireframes
touch doc/prototipo/wireframes/telas_principais.png
touch doc/prototipo/fluxo_navegacao.png

# doc/apresentacoes
mkdir -p doc/apresentacoes/entrega_parcial
mkdir -p doc/apresentacoes/entrega_final
touch doc/apresentacoes/entrega_parcial/slides_entrega_parcial.pdf
touch doc/apresentacoes/entrega_final/slides_entrega_final.pdf

echo ""
echo "Estrutura criada com sucesso!"

read -rp "Deseja criar o projeto Flutter na pasta frontend? (s/n): " FLUTTER_CREATE
if [ "$FLUTTER_CREATE" = "s" ] || [ "$FLUTTER_CREATE" = "S" ]; then
    cd frontend
    flutter create .
    cd ..
fi

echo "Lembre-se de renomear as pastas e arquivos com [dominio] para o dominio do seu projeto."
