export type ApiEnvironment = 'development' | 'staging' | 'production'

// 开发环境地址在运行时解析（见 config/development-server.uts），所以这里必须是 import。
import { developmentApiBaseUrl } from './development-server.uts'

// 2026-09-29：体验版指向攀枝花测试环境。本机联调改回 'development'；生产上线改 'production'。
export const apiEnvironment: ApiEnvironment = 'staging'
// Separate from demo-data controls; only development builds request a test session.
export const developmentLoginBypassEnabled: boolean = false 

// 后台提供合法域名后仅在此处填写，业务页面不得硬编码域名。
// 开发环境地址由 development-server.uts 在启动时自动探测本机局域网 IP，换网后不需要改代码；
// 本机 IP 会变（见过 192.168.110.26 与 192.168.110.15），写死会表现成"登录不上"。
// 必须与微信后台「开发管理 → 服务器域名」里配的完全一致（不带端口时，请求 URL 也不能带端口）。
const stagingBaseUrl = 'https://rencaika.dqrcfwpt.com'
const productionBaseUrl = ''

export const getApiBaseUrl = (): string => {
	if (apiEnvironment == 'production') return productionBaseUrl
	if (apiEnvironment == 'staging') return stagingBaseUrl
	// 每次都现取值：探测是异步完成的，提前取会把启动瞬间的兜底值固化住。
	return developmentApiBaseUrl()
}

export const isApiConfigured = (): boolean => getApiBaseUrl().length > 0

// 路径均由后台联调资料确认后填写；空值会被服务层明确拒绝，避免误请求。
export const getApiEndpoint = (name: string): string => {
	if (name == 'appHome') return '/api/app/home'
	if (name == 'appNews') return '/api/app/news'
	if (name == 'appNewsDetail') return '/api/app/news/'
	if (name == 'appPolicies') return '/api/app/policies'
	if (name == 'appPolicyDetail') return '/api/app/policies/'
	if (name == 'appMerchants') return '/api/app/merchants'
	if (name == 'appMerchantDetail') return '/api/app/merchants/'
	if (name == 'appProducts') return '/api/app/products'
	if (name == 'appProductDetail') return '/api/app/products/'
	if (name == 'appFoodTopic') return '/api/app/topics/food'
	if (name == 'appFoodTopicMerchants') return '/api/app/topics/food/merchants'
	if (name == 'appTravelTopic') return '/api/app/topics/travel'
	if (name == 'appTravelTopicMerchants') return '/api/app/topics/travel/merchants'
	if (name == 'appStayTopic') return '/api/app/topics/stay'
	if (name == 'appStayTopicMerchants') return '/api/app/topics/stay/merchants'
	if (name == 'appEntertainmentTopic') return '/api/app/topics/entertainment'
	if (name == 'appEntertainmentTopicMerchants') return '/api/app/topics/entertainment/merchants'
	if (name == 'appTransportTopic') return '/api/app/topics/transport'
	if (name == 'appTransportTopicMerchants') return '/api/app/topics/transport/merchants'
	if (name == 'appShoppingTopic') return '/api/app/topics/shopping'
	if (name == 'appShoppingTopicMerchants') return '/api/app/topics/shopping/merchants'
	if (name == 'appPremiumTopic') return '/api/app/topics/premium'
	if (name == 'appPremiumTopicServices') return '/api/app/topics/premium/services'
	if (name == 'appSpouseEmploymentBenefit') return '/api/app/spouse-employment-benefits/'
	if (name == 'appAdminApprovalBenefit') return '/api/app/admin-approval-benefits/'
	if (name == 'appFinanceMerchantDetail') return '/api/app/finance-merchants/'
	if (name == 'appChildrenEntrustmentBenefit') return '/api/app/children-entrustment-benefits/'
	if (name == 'appChildrenEntrustmentSchool') return '/api/app/children-entrustment-benefits/schools/'
	if (name == 'appChildren') return '/api/app/children'
	if (name == 'appMedicalMerchantPackages') return '/api/app/medical-merchants/'
	if (name == 'appMedicalPackages') return '/api/app/medical-packages/'
	if (name == 'appServiceAppointmentApplications') return '/api/app/service-appointment-applications'
	if (name == 'appFuelMerchantDetail') return '/api/app/fuel-merchants/'
	if (name == 'appParkingMerchantDetail') return '/api/app/parking-merchants/'
	if (name == 'appParkingPlateSubmissions') return '/api/app/parking-plate-submissions'
	if (name == 'appCarWashMerchantDetail') return '/api/app/car-wash-merchants/'
	if (name == 'appShoppingMerchantDetail') return '/api/app/shopping-merchants/'
	if (name == 'appCinemaMerchants') return '/api/app/cinemas/'
	if (name == 'appCinemaCouponClaims') return '/api/app/cinema-coupon-claims/'
	if (name == 'appTicketPackageClaims') return '/api/app/ticket-packages/claims/'
	if (name == 'appOrderCoupons') return '/api/app/order-drafts/coupons'
	if (name == 'appOrderCouponQuote') return '/api/app/order-drafts/coupon-quote'
	if (name == 'appOrders') return '/api/app/orders'
	if (name == 'appTalentCardProfile') return '/api/app/talent-cards/profile'
	if (name == 'appFamilyCardAccess') return '/api/app/talent-cards/family-card-access'
	if (name == 'appTalentDynamicCode') return '/api/app/talent-cards/'
	if (name == 'appCardUpgrades') return '/api/app/card-upgrades'
	if (name == 'appUsageRecords') return '/api/app/usage-records'
	if (name == 'appPendingOrders') return '/api/app/pending-orders/'
	if (name == 'appPendingUseOrders') return '/api/app/pending-use-orders/'
	if (name == 'appCompletedOrders') return '/api/app/completed-orders/'
	if (name == 'appCancelledOrders') return '/api/app/cancelled-orders/'
	if (name == 'appProcessingApplications') return '/api/app/processing-applications/'
	if (name == 'appFamilyCards') return '/api/app/family-cards/applications'
	if (name == 'appTicketPackages') return '/api/app/ticket-packages'
	if (name == 'appDisplayMerchantPolicies') return '/api/app/display-merchant-policies'
	if (name == 'appFreeBenefits') return '/api/app/free-benefits'
	if (name == 'appBenefitVerificationCodes') return '/api/app/benefit-verification-codes'
	if (name == 'appAgreements') return '/api/app/agreements/'
	if (name == 'appUploadImage') return '/api/app/uploads/images'
	if (name == 'authLogin') return '/api/app/auth/login'
	if (name == 'authDevelopmentSession') return '/api/app/auth/development-session'
	if (name == 'authRefresh') return '/api/app/auth/refresh'
	if (name == 'authLogout') return '/api/app/auth/logout'
	if (name == 'orderCreate') return ''
	if (name == 'orderPayment') return ''
	if (name == 'orderPaymentResult') return ''
	if (name == 'dynamicCode') return ''
	if (name == 'couponClaim') return ''
	if (name == 'couponDetail') return ''
	if (name == 'fileUpload') return '/api/app/uploads/images'
	if (name == 'recordDetail') return ''
	if (name == 'businessSubmit') return ''
	return ''
}
