<?php

namespace Kylin\Wechat\Services;

use Illuminate\Contracts\Container\Container;

/**
 * 微信出行服务类
 */
final class WechatTravelService
{
    /**
     * 构造函数
     */
    public function __construct(
        private readonly Container $app
    ) {}

    /**
     * 打车服务
     */
    public function taxi(array $params, string $driver = 'official_account', string $name = 'default'): array
    {
        $app = $this->getApp($driver, $name);
        
        $result = $app->travel->taxi($params);

        return [
            'code' => 'SUCCESS',
            'message' => '打车服务调用成功',
            'data' => $result
        ];
    }

    /**
     * 共享单车服务
     */
    public function bike(array $params, string $driver = 'official_account', string $name = 'default'): array
    {
        $app = $this->getApp($driver, $name);
        
        $result = $app->travel->bike($params);

        return [
            'code' => 'SUCCESS',
            'message' => '共享单车服务调用成功',
            'data' => $result
        ];
    }

    /**
     * 公共交通服务
     */
    public function transit(array $params, string $driver = 'official_account', string $name = 'default'): array
    {
        $app = $this->getApp($driver, $name);
        
        $result = $app->travel->transit($params);

        return [
            'code' => 'SUCCESS',
            'message' => '公共交通服务调用成功',
            'data' => $result
        ];
    }

    /**
     * 导航服务
     */
    public function navigation(array $params, string $driver = 'official_account', string $name = 'default'): array
    {
        $app = $this->getApp($driver, $name);
        
        $result = $app->travel->navigation($params);

        return [
            'code' => 'SUCCESS',
            'message' => '导航服务调用成功',
            'data' => $result
        ];
    }

    /**
     * 实时路况服务
     */
    public function traffic(array $params, string $driver = 'official_account', string $name = 'default'): array
    {
        $app = $this->getApp($driver, $name);
        
        $result = $app->travel->traffic($params);

        return [
            'code' => 'SUCCESS',
            'message' => '实时路况服务调用成功',
            'data' => $result
        ];
    }

    /**
     * 停车服务
     */
    public function parking(array $params, string $driver = 'official_account', string $name = 'default'): array
    {
        $app = $this->getApp($driver, $name);
        
        $result = $app->travel->parking($params);

        return [
            'code' => 'SUCCESS',
            'message' => '停车服务调用成功',
            'data' => $result
        ];
    }

    /**
     * 加油服务
     */
    public function fuel(array $params, string $driver = 'official_account', string $name = 'default'): array
    {
        $app = $this->getApp($driver, $name);
        
        $result = $app->travel->fuel($params);

        return [
            'code' => 'SUCCESS',
            'message' => '加油服务调用成功',
            'data' => $result
        ];
    }

    /**
     * 充电服务
     */
    public function charging(array $params, string $driver = 'official_account', string $name = 'default'): array
    {
        $app = $this->getApp($driver, $name);
        
        $result = $app->travel->charging($params);

        return [
            'code' => 'SUCCESS',
            'message' => '充电服务调用成功',
            'data' => $result
        ];
    }

    /**
     * 高铁服务
     */
    public function highSpeedRail(array $params, string $driver = 'official_account', string $name = 'default'): array
    {
        $app = $this->getApp($driver, $name);
        
        $result = $app->travel->highSpeedRail($params);

        return [
            'code' => 'SUCCESS',
            'message' => '高铁服务调用成功',
            'data' => $result
        ];
    }

    /**
     * 飞机服务
     */
    public function flight(array $params, string $driver = 'official_account', string $name = 'default'): array
    {
        $app = $this->getApp($driver, $name);
        
        $result = $app->travel->flight($params);

        return [
            'code' => 'SUCCESS',
            'message' => '飞机服务调用成功',
            'data' => $result
        ];
    }

    /**
     * 获取微信应用实例
     */
    protected function getApp(string $driver, string $name = 'default'): mixed
    {
        return $this->app->make('kylin.wechat')->driver($driver, $name);
    }
}
