export async function GET() {
  // This endpoint will help you check your environment variables without exposing them
  const envCheck = {
    SQUARE_ACCESS_TOKEN: {
      exists: !!process.env.SQUARE_ACCESS_TOKEN,
      length: process.env.SQUARE_ACCESS_TOKEN?.length || 0,
      startsWithCorrectPrefix: process.env.SQUARE_ACCESS_TOKEN?.startsWith("EAAA") || false,
      isPlaceholder: process.env.SQUARE_ACCESS_TOKEN === "your_square_access_token_here",
    },
    SQUARE_LOCATION_ID: {
      exists: !!process.env.SQUARE_LOCATION_ID,
      length: process.env.SQUARE_LOCATION_ID?.length || 0,
      startsWithL: process.env.SQUARE_LOCATION_ID?.startsWith("L") || false,
      isPlaceholder: process.env.SQUARE_LOCATION_ID === "your_square_location_id_here",
    },
    SQUARE_ENVIRONMENT: {
      exists: !!process.env.SQUARE_ENVIRONMENT,
      value: process.env.SQUARE_ENVIRONMENT || "not set",
      isValid: ["sandbox", "production"].includes(process.env.SQUARE_ENVIRONMENT || ""),
    },
    NEXT_PUBLIC_SQUARE_APPLICATION_ID: {
      exists: !!process.env.NEXT_PUBLIC_SQUARE_APPLICATION_ID,
      length: process.env.NEXT_PUBLIC_SQUARE_APPLICATION_ID?.length || 0,
      isPlaceholder: process.env.NEXT_PUBLIC_SQUARE_APPLICATION_ID === "your_square_application_id_here",
    },
  }

  return Response.json({
    message: "Environment variables check (values hidden for security)",
    variables: envCheck,
    recommendations: {
      accessToken: !envCheck.SQUARE_ACCESS_TOKEN.exists
        ? "Missing SQUARE_ACCESS_TOKEN"
        : envCheck.SQUARE_ACCESS_TOKEN.isPlaceholder
          ? "Still using placeholder value"
          : !envCheck.SQUARE_ACCESS_TOKEN.startsWithCorrectPrefix
            ? "Token should start with 'EAAA'"
            : "✅ Looks good",
      locationId: !envCheck.SQUARE_LOCATION_ID.exists
        ? "Missing SQUARE_LOCATION_ID"
        : envCheck.SQUARE_LOCATION_ID.isPlaceholder
          ? "Still using placeholder value"
          : !envCheck.SQUARE_LOCATION_ID.startsWithL
            ? "Location ID should start with 'L'"
            : "✅ Looks good",
      environment: !envCheck.SQUARE_ENVIRONMENT.isValid ? "Should be 'sandbox' or 'production'" : "✅ Looks good",
      applicationId: !envCheck.NEXT_PUBLIC_SQUARE_APPLICATION_ID.exists
        ? "Missing NEXT_PUBLIC_SQUARE_APPLICATION_ID"
        : envCheck.NEXT_PUBLIC_SQUARE_APPLICATION_ID.isPlaceholder
          ? "Still using placeholder value"
          : "✅ Looks good",
    },
  })
}
