<?php

namespace FleekDash\Controllers\SiteGrowth;

use WP_Error;
use WP_REST_Request;
use WP_REST_Response;

/**
 * Goals Management Trait for SiteGrowthMeterController
 *
 * Goals system removed - using Achievements system instead
 * This trait maintains backward compatibility with deprecated endpoints
 *
 * @since 2.2.0 Extracted from SiteGrowthMeterController for better organization
 */
trait GoalsManagement
{
    /**
     * Get goals (deprecated - returns empty array)
     */
    public function getGoals(WP_REST_Request $request)
    {
        try {
            $auth = $this->check_auth_graceful('authenticated');

            $active_only = $request->get_param('active_only') === 'true';
            $with_progress = $request->get_param('with_progress') === 'true';

            // Goals system removed - using Achievements system instead
            // Return 410 Gone to clearly communicate deprecation
            return new WP_REST_Response([
                'success' => false,
                'message' => 'Goals system has been removed. Use Achievements system instead.',
                'goals' => [],
                'auth_status' => ($auth['authenticated'] ?? false) ? 'authenticated' : 'fallback'
            ], 410);

        } catch (\Exception $e) {
            return new WP_REST_Response([
                'success' => false,
                'message' => 'Error getting goals: ' . $e->getMessage(),
                'auth_status' => 'error'
            ], 500);
        }
    }

    /**
     * Create custom goal (deprecated)
     */
    public function createGoal(WP_REST_Request $request)
    {
        try {
            $auth = $this->check_auth_graceful('authenticated');

            // Goals system removed - using Achievements system instead
            // Always return 410 Gone to indicate removal
            return new WP_REST_Response([
                'success' => false,
                'message' => 'Goals system has been removed. Use Achievements system instead.',
                'auth_status' => ($auth['authenticated'] ?? false) ? 'authenticated' : 'fallback'
            ], 410);

        } catch (\Exception $e) {
            return new WP_REST_Response([
                'success' => false,
                'message' => 'Error creating goal: ' . $e->getMessage(),
                'auth_status' => 'error'
            ], 500);
        }
    }

    /**
     * Goals system removed - using Achievements system instead
     */
    public function updateGoal(WP_REST_Request $request)
    {
        return new WP_Error('goals_removed', 'Goals system has been removed. Use Achievements system instead.', ['status' => 410]);
    }

    /**
     * Goals system removed - using Achievements system instead
     */
    public function deleteGoal(WP_REST_Request $request)
    {
        return new WP_Error('goals_removed', 'Goals system has been removed. Use Achievements system instead.', ['status' => 410]);
    }
}
