<?php

namespace App\Http\Controllers\Client;

use App\Http\Controllers\Controller;
use App\Services\Client\CommonService;
use Illuminate\Http\Request;

class CommonController extends Controller
{
    protected CommonService $service;

    public function __construct(CommonService $service)
    {
        $this->service = $service;
    }

    /**
     * 获取代理商配置
     */
    public function getConfig(Request $request)
    {
        $agentId = $request->input('agent_id');
        return $this->service->getAgentConfig($agentId);
    }

    /**
     * 获取技师配置
     */
    public function getCoachConfig(Request $request)
    {
        $coachId = $request->input('coach_id');
        return $this->service->getCoachConfig($coachId);
    }

    /**
     * 计算路费金额
     */
    public function calculateDeliveryFee(Request $request)
    {
        $coachId = $request->input('coach_id');
        $agentId = $request->input('agent_id');
        $distance = $request->input('distance');
        $latitude = $request->input('latitude'); 
        $longitude = $request->input('longitude');

        if ($agentId) {
            return $this->service->calculateDeliveryFee($coachId, $agentId, $distance);
        } else {
            return $this->service->calculateDeliveryFeeByLocation($coachId, $latitude, $longitude, $distance);
        }
    }
} 