<?php

// +----------------------------------------------------------------------
// | 星数 [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2023~2024 http://xsframe.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: guiHai <786824455@qq.com>
// +----------------------------------------------------------------------

namespace xsframe\service;

use xsframe\base\BaseService;
use xsframe\wrapper\AttachmentWrapper;

/*
 * 阿里云OSS
 */

class FileService extends BaseService
{
    private $client, $bucket;
    private $attachmentController;

    public function _initialize()
    {
        parent::_initialize(); // TODO: Change the autogenerated stub

        if (!$this->attachmentController instanceof AttachmentWrapper) {
            $this->attachmentController = new AttachmentWrapper();
        }
    }

    //上传文件
    public function uploadFile($filename, $path = ''): string
    {
        try {
            $this->attachmentController->fileRemoteUpload($this->accountSetting, $path, $filename);
            return $filename;
        } catch (OssException $e) {
            return $e->getMessage();
        }
    }

    //删除文件
    public function deleteFile($filename, $bucket = null)
    {
        try {
            // $this->attachmentController->fileDelete($this->accountSetting, $path, $filename);
        } catch (OssException $e) {
            return $e->getMessage();
        }
    }

}